Skip to content

Commit 6eea995

Browse files
author
chetanr25
committed
deleted UserProfile and replaced it with PriceUser
1 parent ef43820 commit 6eea995

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
23
import 'package:http/http.dart' as http;
34
import 'package:openfoodfacts/openfoodfacts.dart';
4-
import 'package:smooth_app/data_models/users_profile_data.dart';
55
import 'package:smooth_app/helpers/launch_url_helper.dart';
66
import 'package:smooth_app/pages/prices/prices_dashboard_widget.dart';
77
import 'package:smooth_app/pages/prices/prices_user_profile.dart';
88
import 'package:smooth_app/query/product_query.dart';
99
import 'package:smooth_app/widgets/smooth_app_bar.dart';
1010
import 'package:smooth_app/widgets/smooth_scaffold.dart';
1111

12-
class PricesDashboard extends StatelessWidget {
13-
PricesDashboard({super.key});
12+
class PricesDashboardPage extends StatelessWidget {
13+
PricesDashboardPage();
1414

15-
late final Future<MaybeError<UserProfile>> _userProfile = _fetchUserProfile();
15+
late final Future<MaybeError<PriceUser>> _userProfile = _fetchUserProfile();
1616

1717
@override
1818
Widget build(BuildContext context) {
19+
final AppLocalizations appLocalizations = AppLocalizations.of(context);
1920
return SmoothScaffold(
2021
appBar: SmoothAppBar(
21-
title: const Text('My Dashboard'),
22+
title: Text(appLocalizations.prices_dashboard_title),
2223
actions: <Widget>[
2324
IconButton(
24-
tooltip: 'Open Prices Dashboard in browser',
25+
tooltip: appLocalizations.prices_dashboard_open_in_browser,
2526
icon: const Icon(Icons.open_in_new),
2627
onPressed: () async => LaunchUrlHelper.launchURL(
2728
OpenPricesAPIClient.getUri(
@@ -32,17 +33,20 @@ class PricesDashboard extends StatelessWidget {
3233
),
3334
],
3435
),
35-
body: FutureBuilder<MaybeError<UserProfile>>(
36+
body: FutureBuilder<MaybeError<PriceUser>>(
3637
future: _userProfile,
3738
builder: (BuildContext context,
38-
AsyncSnapshot<MaybeError<UserProfile>> snapshot) {
39+
AsyncSnapshot<MaybeError<PriceUser>> snapshot) {
3940
if (snapshot.connectionState == ConnectionState.waiting) {
4041
return const Center(child: CircularProgressIndicator());
4142
}
43+
if (snapshot.connectionState != ConnectionState.done) {
44+
return const Center(child: CircularProgressIndicator.adaptive());
45+
}
4246
if (snapshot.hasError) {
4347
return Text(snapshot.error!.toString());
4448
}
45-
final UserProfile userProfile = snapshot.data!.value;
49+
final PriceUser userProfile = snapshot.data!.value;
4650
return Column(
4751
children: <Widget>[
4852
PricesUserProfile(profile: userProfile),
@@ -55,7 +59,7 @@ class PricesDashboard extends StatelessWidget {
5559
}
5660

5761
// TODO(chetanr25): To be implemented in OpenFoodFacts flutter package
58-
static Future<MaybeError<UserProfile>> _fetchUserProfile() async {
62+
static Future<MaybeError<PriceUser>> _fetchUserProfile() async {
5963
final String? userId = OpenFoodAPIConfiguration.globalUser?.userId;
6064
final Uri uri = OpenPricesAPIClient.getUri(
6165
path: '/api/v1/users/$userId',
@@ -66,13 +70,13 @@ class PricesDashboard extends StatelessWidget {
6670
try {
6771
if (response.statusCode == 200) {
6872
final dynamic decodedResponse = HttpHelper().jsonDecodeUtf8(response);
69-
return MaybeError<UserProfile>.value(
70-
UserProfile.fromJson(decodedResponse),
73+
return MaybeError<PriceUser>.value(
74+
PriceUser.fromJson(decodedResponse),
7175
);
7276
}
7377
} catch (e) {
7478
//
7579
}
76-
return MaybeError<UserProfile>.responseError(response);
80+
return MaybeError<PriceUser>.responseError(response);
7781
}
7882
}

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
22

33
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
44
import 'package:openfoodfacts/openfoodfacts.dart';
5-
import 'package:smooth_app/data_models/users_profile_data.dart';
65
import 'package:smooth_app/generic_lib/design_constants.dart';
76
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
87
import 'package:smooth_app/pages/prices/get_prices_model.dart';
@@ -13,13 +12,13 @@ import 'package:smooth_app/query/product_query.dart';
1312

1413
class 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

2120
class _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),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class PricesUserProfile extends StatelessWidget {
6262
IconData icon, int count, String label, BuildContext context,
6363
{Color? color}) {
6464
return SmoothCard(
65-
color: Theme.of(context).colorScheme.onSurface.withAlpha(24),
65+
// color: Theme.of(context).colorScheme.onSurface.withAlpha(24),
6666
child: Container(
6767
width: MediaQuery.sizeOf(context).width / 2 - 3 * LARGE_SPACE,
6868
padding: const EdgeInsets.all(SMALL_SPACE),

0 commit comments

Comments
 (0)