-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(#646): use adaptive dialog wrapper
- Loading branch information
Showing
5 changed files
with
87 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
|
||
import '../module.dart'; | ||
|
||
class AdaptiveDialogWrapper extends StatelessWidget { | ||
const AdaptiveDialogWrapper({ | ||
super.key, | ||
required this.title, | ||
required this.content, | ||
required this.actions, | ||
}); | ||
|
||
final String title; | ||
final Widget? content; | ||
final List<DialogAction> actions; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final materialContent = getPlatform() == SupportedPlatform.ios | ||
? Card( | ||
color: Colors.transparent, | ||
elevation: 0, | ||
child: content, | ||
) | ||
: content; | ||
return AlertDialog.adaptive( | ||
title: Text(title), | ||
content: materialContent, | ||
actions: actions, | ||
); | ||
} | ||
} | ||
|
||
class DialogAction extends StatelessWidget { | ||
const DialogAction({ | ||
super.key, | ||
this.isDestructive = false, | ||
this.onPressed, | ||
required this.text, | ||
}); | ||
|
||
final bool isDestructive; | ||
final void Function()? onPressed; | ||
final String text; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
switch (getPlatform()) { | ||
case SupportedPlatform.ios: | ||
return CupertinoDialogAction( | ||
isDestructiveAction: isDestructive, | ||
onPressed: onPressed, | ||
child: Text(text), | ||
); | ||
default: | ||
return TextButton( | ||
onPressed: onPressed, | ||
child: Text(text, style: onPressed != null | ||
? isDestructive | ||
? TextStyle(color: PharMeTheme.errorColor) | ||
: TextStyle(color: PharMeTheme.primaryColor) | ||
: TextStyle(color: PharMeTheme.onSurfaceColor)), | ||
); | ||
} | ||
} | ||
} |
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