@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
22
33import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
44import 'package:openfoodfacts/openfoodfacts.dart' ;
5- import 'package:smooth_app/data_models/users_profile_data.dart' ;
65import 'package:smooth_app/generic_lib/design_constants.dart' ;
76import 'package:smooth_app/generic_lib/widgets/smooth_card.dart' ;
87import 'package:smooth_app/pages/prices/get_prices_model.dart' ;
@@ -13,13 +12,13 @@ import 'package:smooth_app/query/product_query.dart';
1312
1413class PricesDashboardWidget extends StatefulWidget {
1514 const PricesDashboardWidget ({super .key, required this .userProfile});
16- final UserProfile ? userProfile;
15+ final PriceUser userProfile;
1716 @override
1817 State <PricesDashboardWidget > createState () => _PricesDashboardWidgetState ();
1918}
2019
2120class _PricesDashboardWidgetState extends State <PricesDashboardWidget > {
22- int selectedIndex = 0 ;
21+ String selectedCategory = 'consumption' ;
2322 late Future <MaybeError <GetPricesResult ?>> pricesFuture = _getUserPrices ();
2423
2524 @override
@@ -32,9 +31,9 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
3231 crossAxisAlignment: CrossAxisAlignment .start,
3332 spacing: MEDIUM_SPACE ,
3433 children: < Widget > [
35- categorySwitch (),
34+ _categorySwitch (),
3635 const SizedBox (height: SMALL_SPACE ),
37- priceProofButton (widget.userProfile! , appLocalizations),
36+ _priceProofButton (widget.userProfile, appLocalizations),
3837 FutureBuilder <MaybeError <GetPricesResult ?>>(
3938 future: _getUserPrices (),
4039 builder: (BuildContext context,
@@ -52,7 +51,7 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
5251 title: appLocalizations.prices_generic_title,
5352 parameters: GetPricesParameters (),
5453 uri: OpenPricesAPIClient .getUri (
55- path: 'users/${widget .userProfile ! .userId }' ,
54+ path: 'users/${widget .userProfile .userId }' ,
5655 uriHelper: ProductQuery .uriPricesHelper,
5756 ),
5857 ),
@@ -70,7 +69,7 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
7069 await OpenPricesAPIClient .getPrices (
7170 GetPricesParameters ()
7271 ..owner = OpenFoodAPIConfiguration .globalUser? .userId
73- ..kind = selectedIndex == 0
72+ ..kind = selectedCategory == 'consumption'
7473 ? ContributionKind .consumption
7574 : ContributionKind .community,
7675 uriHelper: ProductQuery .uriPricesHelper,
@@ -79,7 +78,8 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
7978 }
8079
8180 /// Toggle between "My Consumption" and "Other Contributions"
82- Widget categorySwitch () {
81+ Widget _categorySwitch () {
82+ final AppLocalizations appLocalizations = AppLocalizations .of (context);
8383 return Padding (
8484 padding: const EdgeInsets .all (VERY_LARGE_SPACE ),
8585 child: Row (
@@ -88,18 +88,19 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
8888 Expanded (
8989 flex: 1 ,
9090 child: customToggleButton (
91- 0 ,
91+ 'consumption' ,
9292 Icons .shopping_cart,
93- 'Receipts & GDPR requests' ,
93+ appLocalizations.prices_dashboard_receipts_and_gdpr_requests ,
9494 () => setState (() {
95- selectedIndex = 0 ;
95+ selectedCategory = 'consumption' ;
9696 pricesFuture = _getUserPrices ();
9797 }))),
9898 Expanded (
9999 flex: 1 ,
100- child: customToggleButton (1 , Icons .people, 'Price labels' , () {
100+ child: customToggleButton ('community' , Icons .people,
101+ appLocalizations.prices_dashboard_price_labels, () {
101102 setState (() {
102- selectedIndex = 1 ;
103+ selectedCategory = 'community' ;
103104 pricesFuture = _getUserPrices ();
104105 });
105106 }),
@@ -110,10 +111,10 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
110111 }
111112
112113 Widget customToggleButton (
113- int index , IconData icon, String label, VoidCallback onTap) {
114+ String category , IconData icon, String label, VoidCallback onTap) {
114115 final Color selectedColor = Theme .of (context).colorScheme.onSurface;
115116 final Color unselectedColor = selectedColor.withAlpha (128 );
116- final bool isSelected = selectedIndex == index ;
117+ final bool isSelected = selectedCategory == category ;
117118 return GestureDetector (
118119 onTap: onTap,
119120 child: Column (
@@ -151,8 +152,8 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
151152 );
152153 }
153154
154- Widget priceProofButton (
155- UserProfile profile, AppLocalizations appLocalizations) {
155+ Widget _priceProofButton (
156+ PriceUser profile, AppLocalizations appLocalizations) {
156157 return Row (
157158 mainAxisAlignment: MainAxisAlignment .center,
158159 crossAxisAlignment: CrossAxisAlignment .center,
@@ -168,7 +169,7 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
168169 );
169170 },
170171 subtitle: Text (appLocalizations.prices_generic_title),
171- title: Text (selectedIndex == 0
172+ title: Text (selectedCategory == 'consumption'
172173 ? profile.priceKindConsumptionCount.toString ()
173174 : profile.priceKindCommunityCount.toString ()),
174175 trailing: const Icon (Icons .arrow_forward),
@@ -188,7 +189,7 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
188189 );
189190 },
190191 subtitle: Text (appLocalizations.prices_proof_subtitle),
191- title: Text (selectedIndex == 0
192+ title: Text (selectedCategory == 'consumption'
192193 ? profile.proofKindConsumptionCount.toString ()
193194 : profile.proofKindCommunityCount.toString ()),
194195 trailing: const Icon (Icons .arrow_forward),
0 commit comments