Skip to content

Commit

Permalink
feat(#636): adapt dialog wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Dec 20, 2023
1 parent 6a7743e commit 783f663
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 43 deletions.
4 changes: 2 additions & 2 deletions app/lib/common/utilities/drug_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Future<void> updateCachedDrugs() async {
// ignore: use_build_context_synchronously
await showAdaptiveDialog(
context: context,
builder: (context) => AdaptiveDialogWrapper(
builder: (context) => DialogWrapper(
title: context.l10n.update_warning_title,
content: Text(context.l10n.update_warning_body),
content: DialogContentText(context.l10n.update_warning_body),
actions: [
DialogAction(
onPressed: () => Navigator.pop(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,6 @@ 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,
Expand Down Expand Up @@ -63,4 +34,4 @@ class DialogAction extends StatelessWidget {
);
}
}
}
}
14 changes: 14 additions & 0 deletions app/lib/common/widgets/dialog_content_text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import '../module.dart';

class DialogContentText extends StatelessWidget {
const DialogContentText(this.text, {
super.key,
});

final String text;

@override
Widget build(BuildContext context) {
return Text(text, style: PharMeTheme.textTheme.bodyLarge);
}
}
30 changes: 30 additions & 0 deletions app/lib/common/widgets/dialog_wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import '../module.dart';

class DialogWrapper extends StatelessWidget {
const DialogWrapper({
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,
);
}
}
9 changes: 3 additions & 6 deletions app/lib/common/widgets/full_width_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ class FullWidthButton extends StatelessWidget {
child: ElevatedButton(
onPressed: enabled ? action : null,
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32),
),
),
backgroundColor:
MaterialStateProperty.all<Color>(PharMeTheme.primaryColor),
),
child: Text(text),
child: Text(text, style: PharMeTheme.textTheme.bodyLarge),
),
);
}
Expand Down
4 changes: 3 additions & 1 deletion app/lib/common/widgets/module.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export 'adaptive_dialog.dart';
export 'checkbox_list_tile_wrapper.dart';
export 'context_menu.dart';
export 'dialog_action.dart';
export 'dialog_content_text.dart';
export 'dialog_wrapper.dart';
export 'drug_list/builder.dart';
export 'drug_list/cubit.dart';
export 'headings.dart';
Expand Down
6 changes: 4 additions & 2 deletions app/lib/drug/widgets/annotation_cards/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ class DrugAnnotationCard extends StatelessWidget {
if (isInhibitor(drug.name)) {
showAdaptiveDialog(
context: context,
builder: (context) => AdaptiveDialogWrapper(
builder: (context) => DialogWrapper(
title: context.l10n.drugs_page_active_warn_header,
content: Text(context.l10n.drugs_page_active_warn),
content: DialogContentText(
context.l10n.drugs_page_active_warn,
),
actions: [
DialogAction(
onPressed: () => Navigator.pop(context, 'Cancel'),
Expand Down
4 changes: 2 additions & 2 deletions app/lib/more/pages/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class DeleteDataDialog extends HookWidget {
Widget build(BuildContext context) {
final agreedToDeletion = useState(false);

return AdaptiveDialogWrapper(
return DialogWrapper(
title: context.l10n.settings_page_delete_data,
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(context.l10n.settings_page_delete_data_text),
DialogContentText(context.l10n.settings_page_delete_data_text),
SizedBox(height: PharMeTheme.mediumSpace),
CheckboxListTileWrapper(
isChecked: agreedToDeletion.value,
Expand Down

0 comments on commit 783f663

Please sign in to comment.