Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replaced Product Page AppBar with floating action Button #1275

Merged
merged 18 commits into from
Mar 20, 2022
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions packages/smooth_app/lib/pages/product/new_product_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/model/KnowledgePanels.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
Expand Down Expand Up @@ -42,6 +43,7 @@ enum ProductPageMenuItem { WEB, REFRESH }
class _ProductPageState extends State<ProductPage> {
late Product _product;
late ProductPreferences _productPreferences;
bool isVisible = true;

@override
void initState() {
Expand All @@ -63,43 +65,44 @@ class _ProductPageState extends State<ProductPage> {
final ColorScheme colorScheme = themeData.colorScheme;
final MaterialColor materialColor =
SmoothTheme.getMaterialColor(themeProvider);

return Scaffold(
backgroundColor: SmoothTheme.getColor(
colorScheme,
materialColor,
ColorDestination.SURFACE_BACKGROUND,
),
appBar: AppBar(
title: Text(getProductName(_product, appLocalizations)),
actions: <Widget>[
PopupMenuButton<ProductPageMenuItem>(
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<ProductPageMenuItem>>[
PopupMenuItem<ProductPageMenuItem>(
value: ProductPageMenuItem.WEB,
child: Text(appLocalizations.label_web),
),
PopupMenuItem<ProductPageMenuItem>(
value: ProductPageMenuItem.REFRESH,
child: Text(appLocalizations.label_refresh),
M123-dev marked this conversation as resolved.
Show resolved Hide resolved
floatingActionButton: isVisible
? FloatingActionButton(
backgroundColor: colorScheme.primary,
onPressed: () {
Navigator.pop(context);
},
child: const Icon(
Icons.arrow_back,
color: Colors.white,
),
],
onSelected: (final ProductPageMenuItem value) async {
switch (value) {
case ProductPageMenuItem.WEB:
LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/product/${_product.barcode}/',
false);
break;
case ProductPageMenuItem.REFRESH:
_refreshProduct(context);
break;
)
: null,
floatingActionButtonLocation: FloatingActionButtonLocation.startTop,
body: NotificationListener<UserScrollNotification>(
onNotification: (UserScrollNotification notification) {
if (notification.direction == ScrollDirection.forward) {
if (!isVisible) {
setState(() {
isVisible = true;
});
}
},
),
],
),
body: _buildProductBody(context),
} else if (notification.direction == ScrollDirection.reverse) {
if (isVisible) {
setState(() {
isVisible = false;
});
}
}
return true;
},
child: _buildProductBody(context)),
);
}

Expand Down