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: minor design fixes in nutrition_page_loaded.dart #1475

Merged
merged 4 commits into from
Apr 4, 2022
Merged
Changes from 1 commit
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
83 changes: 42 additions & 41 deletions packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:provider/provider.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/pages/product/nutrition_container.dart';

Expand Down Expand Up @@ -83,15 +84,21 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded> {
}
children.add(_addNutrientButton(appLocalizations));
}
children.add(_addCancelSaveButtons(
appLocalizations,
localDatabase,
));

return Scaffold(
appBar: AppBar(title: Text(appLocalizations.nutrition_page_title)),
appBar: AppBar(
title: Text(appLocalizations.nutrition_page_title),
actions: <Widget>[
IconButton(
onPressed: () => _validateAndSave(localDatabase),
VaiTon marked this conversation as resolved.
Show resolved Hide resolved
icon: const Icon(Icons.check))
],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.symmetric(
horizontal: LARGE_SPACE,
vertical: SMALL_SPACE,
),
child: Form(
key: _formKey,
child: ListView(children: children),
Expand Down Expand Up @@ -216,7 +223,7 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded> {
}

Widget _getServingSwitch(final AppLocalizations appLocalizations) => Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(appLocalizations.nutrition_page_per_100g),
Expand All @@ -229,26 +236,27 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded> {
],
);

Widget _switchNoNutrition(final AppLocalizations appLocalizations) =>
Container(
Widget _switchNoNutrition(final AppLocalizations localizations) => SmoothCard(
color: Theme.of(context).colorScheme.primary,
padding: const EdgeInsets.symmetric(
horizontal: MEDIUM_SPACE,
vertical: SMALL_SPACE,
),
margin: EdgeInsets.zero,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Switch(
value: _unspecified,
onChanged: (final bool value) =>
setState(() => _unspecified = !_unspecified),
),
SizedBox(
width: getColumnSizeFromContext(context, 0.6),
child: Text(
appLocalizations.nutrition_page_unspecified,
style: const TextStyle(color: Colors.white),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
Text(
localizations.nutrition_page_unspecified,
style: Theme.of(context).primaryTextTheme.bodyText1,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
Expand All @@ -260,8 +268,10 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded> {
final List<OrderedNutrient> leftovers = List<OrderedNutrient>.from(
_nutritionContainer.getLeftoverNutrients(),
);

leftovers.sort((final OrderedNutrient a, final OrderedNutrient b) =>
a.name!.compareTo(b.name!));

final OrderedNutrient? selected = await showDialog<OrderedNutrient>(
context: context,
builder: (BuildContext context) {
Expand Down Expand Up @@ -294,33 +304,24 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded> {
setState(() => _nutritionContainer.add(selected));
}
},
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: ROUNDED_BORDER_RADIUS,
side: BorderSide.none,
),
),
),
icon: const Icon(Icons.add),
label: Text(appLocalizations.nutrition_page_add_nutrient),
);

Widget _addCancelSaveButtons(
final AppLocalizations appLocalizations,
final LocalDatabase localDatabase,
) =>
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: Text(appLocalizations.cancel),
),
ElevatedButton(
onPressed: () async {
if (!_formKey.currentState!.validate()) {
return;
}
await _save(localDatabase);
},
child: Text(appLocalizations.save),
),
],
);
Future<void> _validateAndSave(final LocalDatabase localDatabase) async {
if (!_formKey.currentState!.validate()) {
return;
}
await _save(localDatabase);
}

Future<void> _save(final LocalDatabase localDatabase) async {
for (final String key in _controllers.keys) {
Expand Down