Skip to content

Commit

Permalink
Same bottom bar with buttons accross screens (#5844)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k authored Nov 14, 2024
1 parent 07a69c2 commit b5e7cb2
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,13 @@ class _CountrySelectorBottomBar extends StatelessWidget {
return EMPTY_WIDGET;
}

final SmoothColorsThemeExtension? colors =
Theme.of(context).extension<SmoothColorsThemeExtension>();

return SmoothButtonsBar2(
animate: true,
backgroundColor:
context.darkTheme() ? colors!.primaryDark : colors!.primaryMedium,
positiveButton: SmoothActionButton2(
text: AppLocalizations.of(context).validate,
icon: const icons.Arrow.right(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
child: Card(child: OwnerFieldInfo()),
),
// in order to be able to scroll suggestions
SizedBox(height: MediaQuery.sizeOf(context).height),
const SizedBox(height: 150),
],
),
),
Expand Down
155 changes: 60 additions & 95 deletions packages/smooth_app/lib/pages/product/add_new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:smooth_app/pages/product/product_image_swipeable_view.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/v2/smooth_buttons_bar.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// "Create a product we couldn't find on the server" page.
Expand Down Expand Up @@ -95,6 +96,7 @@ class _AddNewProductPageState extends State<AddNewProductPage>
(widget.displayPictures ? 1 : 0);

double get _progress => (_pageNumber + 1) / _totalPages;

bool get _isLastPage => (_pageNumber + 1) == _totalPages;
ProductType? _inputProductType;
late ColorScheme _colorScheme;
Expand Down Expand Up @@ -272,14 +274,7 @@ class _AddNewProductPageState extends State<AddNewProductPage>
],
),
),
Card(
margin: EdgeInsets.zero,
elevation: 15.0,
child: SizedBox(
height: MediaQuery.sizeOf(context).height * 0.1,
child: _getButtons(),
),
)
_getButtons(),
],
),
),
Expand Down Expand Up @@ -351,31 +346,56 @@ class _AddNewProductPageState extends State<AddNewProductPage>

Widget _getButtons() {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: Size(MediaQuery.sizeOf(context).width * 0.35, 40.0),
backgroundColor: _colorScheme.secondary,
shape: const RoundedRectangleBorder(
borderRadius: ROUNDED_BORDER_RADIUS,
),
),
onPressed: () async {
if (_pageNumber == 0) {
Navigator.of(context).maybePop();
return;
}
if (widget.displayProductType && _pageNumber == 1) {

return SmoothButtonsBar2(
negativeButton: SmoothActionButton2(
text: _pageNumber >= 1
? appLocalizations.previous_label
: appLocalizations.cancel,
onPressed: () async {
if (_pageNumber == 0) {
Navigator.of(context).maybePop();
return;
}
if (widget.displayProductType && _pageNumber == 1) {
return showDialog(
context: context,
builder: (final BuildContext context) => SmoothAlertDialog(
title: appLocalizations.product_type_selection_title,
body: Text(
appLocalizations.product_type_selection_already(
upToDateProduct.productType!.getLabel(appLocalizations),
),
),
positiveAction: SmoothActionButton(
text: appLocalizations.okay,
onPressed: () => Navigator.of(context).pop(),
),
),
);
}
_pageController.previousPage(
duration: SmoothAnimationsDuration.short,
curve: Curves.easeOut,
);
},
),
positiveButton: SmoothActionButton2(
text:
_isLastPage ? appLocalizations.finish : appLocalizations.next_label,
onPressed: () async {
if (_isLastPage) {
Navigator.of(context).pop();
return;
}
if (widget.displayProductType && _pageNumber == 0) {
if (_inputProductType == null) {
return showDialog(
context: context,
builder: (final BuildContext context) => SmoothAlertDialog(
title: appLocalizations.product_type_selection_title,
body: Text(
appLocalizations.product_type_selection_already(
upToDateProduct.productType!.getLabel(appLocalizations),
),
appLocalizations.product_type_selection_empty,
),
positiveAction: SmoothActionButton(
text: appLocalizations.okay,
Expand All @@ -384,74 +404,19 @@ class _AddNewProductPageState extends State<AddNewProductPage>
),
);
}
_pageController.previousPage(
duration: SmoothAnimationsDuration.short,
curve: Curves.easeOut,
await BackgroundTaskDetails.addTask(
Product(barcode: barcode)..productType = _inputProductType,
context: context,
stamp: BackgroundTaskDetailsStamp.productType,
productType: _inputProductType,
);
},
child: Text(
_pageNumber >= 1
? appLocalizations.previous_label
: appLocalizations.cancel,
style: const TextStyle(
color: Colors.black,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: BALANCED_SPACE),
ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: Size(MediaQuery.sizeOf(context).width * 0.35, 40.0),
backgroundColor: DARK_BROWN_COLOR,
shape: const RoundedRectangleBorder(
borderRadius: ROUNDED_BORDER_RADIUS,
),
),
onPressed: () async {
if (_isLastPage) {
Navigator.of(context).pop();
return;
}
if (widget.displayProductType && _pageNumber == 0) {
if (_inputProductType == null) {
return showDialog(
context: context,
builder: (final BuildContext context) => SmoothAlertDialog(
title: appLocalizations.product_type_selection_title,
body: Text(
appLocalizations.product_type_selection_empty,
),
positiveAction: SmoothActionButton(
text: appLocalizations.okay,
onPressed: () => Navigator.of(context).pop(),
),
),
);
}
await BackgroundTaskDetails.addTask(
Product(barcode: barcode)..productType = _inputProductType,
context: context,
stamp: BackgroundTaskDetailsStamp.productType,
productType: _inputProductType,
);
}
_pageController.nextPage(
duration: SmoothAnimationsDuration.short,
curve: Curves.easeOut,
);
},
child: Text(
_isLastPage ? appLocalizations.finish : appLocalizations.next_label,
style: const TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
)
],
}
_pageController.nextPage(
duration: SmoothAnimationsDuration.short,
curve: Curves.easeOut,
);
},
),
);
}

Expand Down
23 changes: 9 additions & 14 deletions packages/smooth_app/lib/pages/product/common/product_buttons.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/widgets/v2/smooth_buttons_bar.dart';

/// A button bar containing two actions : Save and Cancel
/// To ensure a fully working scroll, please set the [fixKeyboard] attribute in
Expand All @@ -20,18 +19,14 @@ class ProductBottomButtonsBar extends StatelessWidget {
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);

return SafeArea(
child: SmoothActionButtonsBar(
axis: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: LARGE_SPACE),
positiveAction: SmoothActionButton(
text: appLocalizations.save,
onPressed: onSave,
),
negativeAction: SmoothActionButton(
text: appLocalizations.cancel,
onPressed: onCancel,
),
return SmoothButtonsBar2(
positiveButton: SmoothActionButton2(
text: appLocalizations.save,
onPressed: onSave,
),
negativeButton: SmoothActionButton2(
text: appLocalizations.cancel,
onPressed: onCancel,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:smooth_app/pages/product/product_image_button.dart';
import 'package:smooth_app/themes/smooth_theme_colors.dart';
import 'package:smooth_app/themes/theme_provider.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/v2/smooth_buttons_bar.dart';

part 'edit_ocr_main_action.dart';

Expand Down Expand Up @@ -397,13 +398,8 @@ class _EditOcrPageState extends State<EditOcrPage> with UpToDateMixin {
),
),
),
SmoothActionButtonsBar(
axis: Axis.horizontal,
negativeAction: SmoothActionButton(
text: appLocalizations.cancel,
onPressed: () => Navigator.pop(context),
),
positiveAction: SmoothActionButton(
SmoothButtonsBar2(
positiveButton: SmoothActionButton2(
text: appLocalizations.save,
onPressed: () async {
await _updateText();
Expand All @@ -413,8 +409,11 @@ class _EditOcrPageState extends State<EditOcrPage> with UpToDateMixin {
Navigator.pop(context);
},
),
negativeButton: SmoothActionButton2(
text: appLocalizations.cancel,
onPressed: () => Navigator.pop(context),
),
),
SizedBox(height: MediaQuery.paddingOf(context).bottom),
],
),
);
Expand Down
10 changes: 7 additions & 3 deletions packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,19 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded>
product: upToDateProduct,
),
body: Padding(
padding: const EdgeInsets.symmetric(
padding: const EdgeInsetsDirectional.symmetric(
horizontal: LARGE_SPACE,
vertical: SMALL_SPACE,
),
child: Form(
key: _formKey,
child: Provider<List<FocusNode>>.value(
value: _focusNodes,
child: ListView(children: children),
child: ListView(
padding: const EdgeInsetsDirectional.symmetric(
vertical: SMALL_SPACE,
),
children: children,
),
),
),
),
Expand Down
13 changes: 12 additions & 1 deletion packages/smooth_app/lib/pages/product/simple_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/product/owner_field_info.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';
import 'package:smooth_app/pages/product/simple_input_widget.dart';
import 'package:smooth_app/themes/smooth_theme_colors.dart';
import 'package:smooth_app/themes/theme_provider.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

Expand Down Expand Up @@ -111,8 +113,17 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
title: titles.join(', '),
product: widget.product,
),
backgroundColor: context.lightTheme()
? Theme.of(context)
.extension<SmoothColorsThemeExtension>()!
.primaryLight
: null,
body: Padding(
padding: const EdgeInsets.all(SMALL_SPACE),
padding: const EdgeInsetsDirectional.only(
top: SMALL_SPACE,
start: SMALL_SPACE,
end: SMALL_SPACE,
),
child: Scrollbar(
child: ListView(children: simpleInputs),
),
Expand Down
Loading

0 comments on commit b5e7cb2

Please sign in to comment.