Files
smooth-app/packages/smooth_app/lib/widgets/attribute_button.dart
monsieurtanuki f1045c4cac feat: #870 - new UI for attribute buttons and user preference titles (#871)
Deleted files:
* `attribute_dialog.dart`
* `important.svg`
* `mandatory.svg`

Impacted files:
* `abstract_user_preferences.dart`: aligns the title of the header with the expand/collapse icon, and with a compact mode
* `attribute_button.dart`: removed the attribute dialog and put a button instead
* `attribute_helper.dart`: removed was not relevant anymore, and there's not much left!
* `user_preferences_attribute_group.dart`: different text style and compact title, no more reordering
* `user_preferences_page-blue-dark.png`: golden refresh
* `user_preferences_page-blue-light.png`: golden refresh
* `user_preferences_page-brown-dark.png`: golden refresh
* `user_preferences_page-brown-light.png`: golden refresh
* `user_preferences_page-green-dark.png`: golden refresh
* `user_preferences_page-green-light.png`: golden refresh
2022-01-07 16:05:13 +01:00

74 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:openfoodfacts/model/Attribute.dart';
import 'package:openfoodfacts/personalized_search/preference_importance.dart';
import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_ui_library/util/ui_helpers.dart';
/// Colored button for attribute importance, with corresponding action
class AttributeButton extends StatelessWidget {
const AttributeButton(
this.attribute,
this.productPreferences,
);
final Attribute attribute;
final ProductPreferences productPreferences;
static const Map<String, String> _nextValues = <String, String>{
PreferenceImportance.ID_NOT_IMPORTANT: PreferenceImportance.ID_IMPORTANT,
PreferenceImportance.ID_IMPORTANT: PreferenceImportance.ID_MANDATORY,
PreferenceImportance.ID_MANDATORY: PreferenceImportance.ID_NOT_IMPORTANT,
};
static const Map<String, Color> _colors = <String, Color>{
PreferenceImportance.ID_NOT_IMPORTANT: Color(0xFF666666),
PreferenceImportance.ID_IMPORTANT: Colors.blue,
PreferenceImportance.ID_MANDATORY: Colors.red,
};
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
String importanceId =
productPreferences.getImportanceIdForAttributeId(attribute.id!);
// We switch from 4 to 3 choices: very important is downgraded to important
if (importanceId == PreferenceImportance.ID_VERY_IMPORTANT) {
importanceId = PreferenceImportance.ID_IMPORTANT;
}
const double horizontalPadding = LARGE_SPACE;
final double screenWidth =
MediaQuery.of(context).size.width - 2 * horizontalPadding;
final TextStyle style = themeData.textTheme.headline3!;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: horizontalPadding),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
width: screenWidth * .45,
child: Text(attribute.name!, style: style),
),
SizedBox(
width: screenWidth * .45,
child: ElevatedButton(
child: Text(
productPreferences
.getPreferenceImportanceFromImportanceId(importanceId)!
.name!,
style: style.copyWith(color: Colors.white),
),
style: ElevatedButton.styleFrom(
primary: _colors[importanceId],
onPrimary: Colors.white,
),
onPressed: () async => productPreferences.setImportance(
attribute.id!, _nextValues[importanceId]!),
),
),
],
),
);
}
}