-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use adaptive dialog action
- Loading branch information
1 parent
416cdc1
commit d1e211a
Showing
9 changed files
with
60 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
extension SizeString on num { | ||
String get sizeString { | ||
var size = toDouble(); | ||
if (size < 1000000) { | ||
if (size < 1000) { | ||
return '${size.round()} Bytes'; | ||
} | ||
if (size < 1000 * 1000) { | ||
size = size / 1000; | ||
size = (size * 10).round() / 10; | ||
return '${size.toString()} KB'; | ||
} else if (size < 1000000000) { | ||
} | ||
if (size < 1000 * 1000 * 1000) { | ||
size = size / 1000000; | ||
size = (size * 10).round() / 10; | ||
return '${size.toString()} MB'; | ||
} else { | ||
size = size / 1000000000; | ||
size = (size * 10).round() / 10; | ||
return '${size.toString()} GB'; | ||
} | ||
size = size / 1000 * 1000 * 1000 * 1000; | ||
size = (size * 10).round() / 10; | ||
return '${size.toString()} GB'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class AdaptiveDialogAction extends StatelessWidget { | ||
final VoidCallback? onPressed; | ||
final Widget child; | ||
|
||
const AdaptiveDialogAction({ | ||
super.key, | ||
required this.onPressed, | ||
required this.child, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
switch (theme.platform) { | ||
case TargetPlatform.android: | ||
case TargetPlatform.fuchsia: | ||
case TargetPlatform.linux: | ||
case TargetPlatform.windows: | ||
return TextButton(onPressed: onPressed, child: child); | ||
case TargetPlatform.iOS: | ||
case TargetPlatform.macOS: | ||
return CupertinoDialogAction(onPressed: onPressed, child: child); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters