Skip to content

Commit

Permalink
fix: SmoothSimpleButton reactive to schema openfoodfacts#591 (openfoo…
Browse files Browse the repository at this point in the history
…dfacts#624)

* fix: SmoothSimpleButton reactive to schema openfoodfacts#591

* chore: remove important flag

* fix: remove important flag calls on smooth buttoncalls

* fix: remove important flag call

* Revert "chore: remove important flag"

This reverts commit 37fa220.

* fix: review changes

Co-authored-by: dannylo-gaivota <80546050+dannylo-gaivota@users.noreply.github.com>
  • Loading branch information
eudangeld and dannylo-gaivota authored Oct 18, 2021
1 parent 36a1d89 commit ff8858e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class ProductDialogHelper {
actions: <SmoothSimpleButton>[
SmoothSimpleButton(
text: AppLocalizations.of(context)!.stop,
important: false,
onPressed: () => _popSearchingDialog(null),
),
],
Expand All @@ -93,12 +92,11 @@ class ProductDialogHelper {
actions: <SmoothSimpleButton>[
SmoothSimpleButton(
text: AppLocalizations.of(context)!.close,
important: false,
onPressed: () => Navigator.pop(context),
),
SmoothSimpleButton(
text: AppLocalizations.of(context)!.contribute,
important: true,

onPressed: () => Navigator.pop(
context), // TODO(monsieurtanuki): to be implemented
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ class ProductListDialogHelper {
actions: <SmoothSimpleButton>[
SmoothSimpleButton(
text: AppLocalizations.of(context)!.no,
important: false,
onPressed: () => Navigator.pop(context, false),
),
SmoothSimpleButton(
text: AppLocalizations.of(context)!.yes,
important: true,
onPressed: () async {
await daoProductList.delete(productList);
Navigator.pop(context, true);
Expand Down Expand Up @@ -94,10 +92,8 @@ class ProductListDialogHelper {
),
actions: <SmoothSimpleButton>[
SmoothSimpleButton(
text: appLocalizations.cancel,
onPressed: () => Navigator.pop(context, null),
important: false,
),
text: appLocalizations.cancel,
onPressed: () => Navigator.pop(context, null)),
SmoothSimpleButton(
text: appLocalizations.okay,
onPressed: () async {
Expand All @@ -108,7 +104,6 @@ class ProductListDialogHelper {
await daoProductList.put(newProductList!);
Navigator.pop(context, newProductList);
},
important: true,
),
],
),
Expand Down Expand Up @@ -166,26 +161,22 @@ class ProductListDialogHelper {
),
actions: <SmoothSimpleButton>[
SmoothSimpleButton(
text: appLocalizations.cancel,
onPressed: () => Navigator.pop(context, null),
important: false,
),
text: appLocalizations.cancel,
onPressed: () => Navigator.pop(context, null)),
SmoothSimpleButton(
text: AppLocalizations.of(context)!.okay,
onPressed: () async {
if (!formKey.currentState!.validate()) {
return;
}
if (!await daoProductList.rename(
productList, newProductList!.parameters)) {
// TODO(monsieurtanuki): unexpected, but do something!
return;
}
await daoProductList.get(newProductList!);
Navigator.pop(context, newProductList);
},
important: true,
),
text: AppLocalizations.of(context)!.okay,
onPressed: () async {
if (!formKey.currentState!.validate()) {
return;
}
if (!await daoProductList.rename(
productList, newProductList!.parameters)) {
// TODO(monsieurtanuki): unexpected, but do something!
return;
}
await daoProductList.get(newProductList!);
Navigator.pop(context, newProductList);
}),
],
),
);
Expand Down Expand Up @@ -239,7 +230,6 @@ class ProductListDialogHelper {
SmoothSimpleButton(
text: appLocalizations.cancel,
onPressed: () => Navigator.pop(context, false),
important: false,
),
],
),
Expand Down
42 changes: 19 additions & 23 deletions packages/smooth_ui_library/lib/buttons/smooth_simple_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,32 @@ class SmoothSimpleButton extends StatelessWidget {
required this.onPressed,
this.minWidth = 15,
this.height = 20,
this.important = true,
});

final String text;
final VoidCallback onPressed;
final double minWidth;
final double height;
final bool important;

@override
Widget build(BuildContext context) => MaterialButton(
color: important
? Theme.of(context).colorScheme.secondary
: Theme.of(context).colorScheme.onSecondary,
child: Padding(
padding: const EdgeInsets.all(10),
child: Text(
text,
style: Theme.of(context).textTheme.bodyText2!.copyWith(
color: important
? Theme.of(context).colorScheme.onSecondary
: Theme.of(context).colorScheme.secondary,
),
),
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
return MaterialButton(
color: themeData.colorScheme.primary,
child: Padding(
padding: const EdgeInsets.all(10),
child: Text(
text,
style: themeData.textTheme.bodyText2!
.copyWith(color: themeData.colorScheme.onPrimary),
),
height: height,
minWidth: minWidth,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
onPressed: () => onPressed(),
);
),
height: height,
minWidth: minWidth,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
onPressed: () => onPressed(),
);
}
}

0 comments on commit ff8858e

Please sign in to comment.