Files
smooth-app/packages/smooth_app/lib/widgets/attribute_button.dart
monsieurtanuki 7e861f569e refactor: upgrade to off-dart 2.0.0 (#3495)
Impacted files:
* `paged_to_be_completed_product_query.dart`: renamed `State` as `ProductState`
* `paged_user_product_query.dart`: created local `UserSearchType` instead of deprecated off-dart `UserProductSearchType`; used `ProductSearchQueryConfiguration` instead of deprecated `UserProductSearchQueryConfiguration`
* `product_query.dart`: now that we use fully v3, we don't need the temporary field list for user-related queries with v2
* `pubspec.lock`: wtf
* `pubspec.yaml`: upgrade to off-dart 2.0.0
* `user_preferences_account.dart`: now using new local class `UserSearchType`
* and reduced all off-dart imports to a single `import 'package:openfoodfacts/openfoodfacts.dart';`
2023-01-02 16:10:52 +01:00

116 lines
4.1 KiB
Dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.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 List<String> _importanceIds = <String>[
PreferenceImportance.ID_NOT_IMPORTANT,
PreferenceImportance.ID_IMPORTANT,
PreferenceImportance.ID_VERY_IMPORTANT,
PreferenceImportance.ID_MANDATORY,
];
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
final String currentImportanceId =
productPreferences.getImportanceIdForAttributeId(attribute.id!);
const double horizontalPadding = LARGE_SPACE;
final double widgetWidth =
MediaQuery.of(context).size.width - 2 * horizontalPadding;
final double importanceWidth = widgetWidth / 4;
final TextStyle style = themeData.textTheme.headline4!;
final String? info = attribute.settingNote;
final List<Widget> children = <Widget>[];
for (final String importanceId in _importanceIds) {
children.add(
Expanded(
child: InkWell(
onTap: () async => productPreferences.setImportance(
attribute.id!,
importanceId,
),
child: Container(
width: importanceWidth,
constraints: const BoxConstraints(minHeight: MINIMUM_TOUCH_SIZE),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(
currentImportanceId == importanceId
? Icons.radio_button_checked
: Icons.radio_button_off,
color: themeData.colorScheme.primary,
),
AutoSizeText(
productPreferences
.getPreferenceImportanceFromImportanceId(importanceId)!
.name!,
maxLines: 2,
textAlign: TextAlign.center,
),
],
),
),
),
),
);
}
return Padding(
padding: const EdgeInsets.symmetric(
vertical: SMALL_SPACE,
horizontal: horizontalPadding,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ListTile(
trailing: info == null ? null : const Icon(Icons.info_outline),
title: AutoSizeText(
attribute.settingName ?? attribute.name!,
maxLines: 2,
style: style,
),
onTap: info == null
? null
: () async => showDialog<void>(
context: context,
builder: (BuildContext context) {
final AppLocalizations appLocalizations =
AppLocalizations.of(context);
return SmoothAlertDialog(
body: Text(info),
positiveAction: SmoothActionButton(
text: appLocalizations.close,
onPressed: () => Navigator.pop(context),
),
);
},
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
),
],
),
);
}
}