Skip to content

Commit 7075c4d

Browse files
author
chetanr25
committed
Scrolling issue fixed, minor UI improvements
1 parent efed84a commit 7075c4d

File tree

2 files changed

+61
-26
lines changed

2 files changed

+61
-26
lines changed

packages/smooth_app/lib/pages/prices/prices_dashboard_page.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
33
import 'package:openfoodfacts/openfoodfacts.dart';
4+
import 'package:smooth_app/generic_lib/design_constants.dart';
45
import 'package:smooth_app/helpers/launch_url_helper.dart';
56
import 'package:smooth_app/pages/prices/prices_dashboard_widget.dart';
67
import 'package:smooth_app/pages/prices/prices_user_profile.dart';
@@ -48,12 +49,14 @@ class PricesDashboardPage extends StatelessWidget {
4849
return Text(snapshot.error!.toString());
4950
}
5051
final PriceUser userProfile = snapshot.data!.value;
51-
return Column(
52-
children: <Widget>[
53-
PricesUserProfile(profile: userProfile),
54-
Expanded(
55-
child: PricesDashboardWidget(userProfile: userProfile)),
56-
],
52+
return SingleChildScrollView(
53+
child: Column(
54+
children: <Widget>[
55+
PricesUserProfile(profile: userProfile),
56+
PricesDashboardWidget(userProfile: userProfile),
57+
const SizedBox(height: VERY_LARGE_SPACE),
58+
],
59+
),
5760
);
5861
}),
5962
);

packages/smooth_app/lib/pages/prices/prices_dashboard_widget.dart

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import 'package:openfoodfacts/openfoodfacts.dart';
55
import 'package:smooth_app/generic_lib/design_constants.dart';
66
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
77
import 'package:smooth_app/pages/prices/get_prices_model.dart';
8+
import 'package:smooth_app/pages/prices/price_data_widget.dart';
9+
import 'package:smooth_app/pages/prices/price_product_widget.dart';
810
import 'package:smooth_app/pages/prices/price_user_button.dart';
911
import 'package:smooth_app/pages/prices/prices_proofs_page.dart';
10-
import 'package:smooth_app/pages/prices/product_prices_list.dart';
1112
import 'package:smooth_app/query/product_query.dart';
1213

1314
class PricesDashboardWidget extends StatefulWidget {
@@ -24,12 +25,10 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
2425
@override
2526
Widget build(BuildContext context) {
2627
final AppLocalizations appLocalizations = AppLocalizations.of(context);
27-
2828
return Column(
2929
mainAxisSize: MainAxisSize.min,
3030
mainAxisAlignment: MainAxisAlignment.start,
3131
crossAxisAlignment: CrossAxisAlignment.start,
32-
spacing: MEDIUM_SPACE,
3332
children: <Widget>[
3433
_categorySwitch(),
3534
const SizedBox(height: SMALL_SPACE),
@@ -45,36 +44,69 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
4544
return Center(child: Text(snapshot.error.toString()));
4645
}
4746

48-
return Expanded(
49-
child: ProductPricesList(
50-
GetPricesModel(
51-
title: appLocalizations.prices_generic_title,
52-
parameters: GetPricesParameters(),
53-
uri: OpenPricesAPIClient.getUri(
54-
path: 'users/${widget.userProfile.userId}',
55-
uriHelper: ProductQuery.uriPricesHelper,
56-
),
47+
if (snapshot.data?.value == null ||
48+
snapshot.data?.value!.items == null ||
49+
snapshot.data!.value!.items!.isEmpty) {
50+
return const Center(
51+
child: Padding(
52+
padding: EdgeInsets.all(LARGE_SPACE),
53+
child:
54+
Text('No prices found', style: TextStyle(fontSize: 14)),
5755
),
58-
pricesResult: snapshot.data!.value,
56+
);
57+
}
58+
final List<Price> prices = snapshot.data!.value!.items!;
59+
60+
final GetPricesModel model = GetPricesModel(
61+
title: appLocalizations.prices_generic_title,
62+
parameters: GetPricesParameters()
63+
..owner = widget.userProfile.userId
64+
..kind = selectedCategory == 'consumption'
65+
? ContributionKind.consumption
66+
: ContributionKind.community,
67+
uri: OpenPricesAPIClient.getUri(
68+
path: 'users/${widget.userProfile.userId}',
69+
uriHelper: ProductQuery.uriPricesHelper,
5970
),
6071
);
72+
73+
return Column(
74+
children: prices.map((Price item) {
75+
final PriceProduct? priceProduct = item.product;
76+
return SmoothCard(
77+
child: Column(
78+
mainAxisAlignment: MainAxisAlignment.start,
79+
crossAxisAlignment: CrossAxisAlignment.start,
80+
children: <Widget>[
81+
if (model.displayEachProduct && priceProduct != null)
82+
PriceProductWidget(
83+
priceProduct,
84+
enableCountButton: model.enableCountButton,
85+
),
86+
PriceDataWidget(
87+
item,
88+
model: model,
89+
),
90+
],
91+
),
92+
);
93+
}).toList(),
94+
);
6195
},
6296
),
6397
],
6498
);
6599
}
66100

67101
Future<MaybeError<GetPricesResult?>> _getUserPrices() async {
68-
final MaybeError<GetPricesResult?> prices =
69-
await OpenPricesAPIClient.getPrices(
102+
return OpenPricesAPIClient.getPrices(
70103
GetPricesParameters()
71-
..owner = OpenFoodAPIConfiguration.globalUser?.userId
104+
..owner = widget.userProfile.userId
72105
..kind = selectedCategory == 'consumption'
73106
? ContributionKind.consumption
74107
: ContributionKind.community,
75108
uriHelper: ProductQuery.uriPricesHelper,
76109
);
77-
return prices;
78110
}
79111

80112
/// Toggle between "My Consumption" and "Other Contributions"
@@ -87,7 +119,7 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
87119
children: <Widget>[
88120
Expanded(
89121
flex: 1,
90-
child: customToggleButton(
122+
child: _categoryToggleButton(
91123
'consumption',
92124
Icons.shopping_cart,
93125
appLocalizations.prices_dashboard_receipts_and_gdpr_requests,
@@ -97,7 +129,7 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
97129
}))),
98130
Expanded(
99131
flex: 1,
100-
child: customToggleButton('community', Icons.people,
132+
child: _categoryToggleButton('community', Icons.people,
101133
appLocalizations.prices_dashboard_price_labels, () {
102134
setState(() {
103135
selectedCategory = 'community';
@@ -110,7 +142,7 @@ class _PricesDashboardWidgetState extends State<PricesDashboardWidget> {
110142
);
111143
}
112144

113-
Widget customToggleButton(
145+
Widget _categoryToggleButton(
114146
String category, IconData icon, String label, VoidCallback onTap) {
115147
final Color selectedColor = Theme.of(context).colorScheme.onSurface;
116148
final Color unselectedColor = selectedColor.withAlpha(128);

0 commit comments

Comments
 (0)