Skip to content

Commit a92442e

Browse files
committed
Disabled feedback for web
- RemoteConfig is not supported on web
1 parent bc97ffb commit a92442e

File tree

5 files changed

+136
-106
lines changed

5 files changed

+136
-106
lines changed

lib/pages/classes/view/class_view.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:provider/provider.dart';
77

88
import '../../../authentication/service/auth_provider.dart';
99
import '../../../generated/l10n.dart';
10-
import '../../../resources/remote_config.dart';
1110
import '../../../resources/utils.dart';
1211
import '../../../widgets/button.dart';
1312
import '../../../widgets/class_icon.dart';
@@ -60,7 +59,7 @@ class _ClassViewState extends State<ClassView> {
6059
return AppScaffold(
6160
title: Text(S.current.navigationClassInfo),
6261
actions: [
63-
if (RemoteConfigService.feedbackEnabled)
62+
if (Utils.feedbackEnabled)
6463
AppScaffoldAction(
6564
icon: Icons.rate_review_outlined,
6665
tooltip: S.current.navigationClassFeedback,

lib/pages/classes/view/classes_page.dart

+119-94
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:provider/provider.dart';
44

55
import '../../../authentication/service/auth_provider.dart';
66
import '../../../generated/l10n.dart';
7-
import '../../../resources/remote_config.dart';
7+
import '../../../resources/utils.dart';
88
import '../../../widgets/class_icon.dart';
99
import '../../../widgets/error_page.dart';
1010
import '../../../widgets/icon_text.dart';
@@ -34,9 +34,9 @@ class _ClassesPageState extends State<ClassesPage> {
3434
}
3535

3636
final ClassProvider classProvider =
37-
Provider.of<ClassProvider>(context, listen: false);
37+
Provider.of<ClassProvider>(context, listen: false);
3838
final AuthProvider authProvider =
39-
Provider.of<AuthProvider>(context, listen: false);
39+
Provider.of<AuthProvider>(context, listen: false);
4040
headers =
4141
(await classProvider.fetchClassHeaders(uid: authProvider.uid)).toSet();
4242

@@ -63,87 +63,100 @@ class _ClassesPageState extends State<ClassesPage> {
6363
// TODO(IoanaAlexandru): Simply show all classes if user is not authenticated
6464
needsToBeAuthenticated: true,
6565
actions: [
66-
if (RemoteConfigService.feedbackEnabled)
66+
if (Utils.feedbackEnabled)
6767
AppScaffoldAction(
6868
icon: Icons.rate_review_outlined,
6969
tooltip: S.current.navigationClassesFeedbackChecklist,
70-
onPressed: () => Navigator.of(context).push(
71-
MaterialPageRoute<ClassFeedbackChecklist>(
72-
builder: (_) => ClassFeedbackChecklist(classes: headers),
73-
),
74-
),
70+
onPressed: () =>
71+
Navigator.of(context).push(
72+
MaterialPageRoute<ClassFeedbackChecklist>(
73+
builder: (_) => ClassFeedbackChecklist(classes: headers),
74+
),
75+
),
7576
),
7677
AppScaffoldAction(
7778
icon: Icons.edit_outlined,
7879
tooltip: S.current.actionChooseClasses,
79-
onPressed: () => Navigator.of(context).push(
80-
MaterialPageRoute<ChangeNotifierProvider>(
81-
builder: (_) => ChangeNotifierProvider.value(
82-
value: classProvider,
83-
child: FutureBuilder(
84-
future: classProvider.fetchUserClassIds(authProvider.uid),
85-
builder: (context, snap) {
86-
if (snap.hasData) {
87-
return AddClassesPage(
88-
initialClassIds: snap.data,
89-
onSave: (classIds) async {
90-
await classProvider.setUserClassIds(
91-
classIds, authProvider.uid);
92-
unawaited(updateClasses());
93-
if (!mounted) {
94-
return;
80+
onPressed: () =>
81+
Navigator.of(context).push(
82+
MaterialPageRoute<ChangeNotifierProvider>(
83+
builder: (_) =>
84+
ChangeNotifierProvider.value(
85+
value: classProvider,
86+
child: FutureBuilder(
87+
future: classProvider.fetchUserClassIds(
88+
authProvider.uid),
89+
builder: (context, snap) {
90+
if (snap.hasData) {
91+
return AddClassesPage(
92+
initialClassIds: snap.data,
93+
onSave: (classIds) async {
94+
await classProvider.setUserClassIds(
95+
classIds, authProvider.uid);
96+
unawaited(updateClasses());
97+
if (!mounted) {
98+
return;
99+
}
100+
Navigator.pop(context);
101+
});
102+
} else {
103+
return const Center(
104+
child: CircularProgressIndicator());
95105
}
96-
Navigator.pop(context);
97-
});
98-
} else {
99-
return const Center(child: CircularProgressIndicator());
100-
}
101-
},
102-
)),
103-
),
104-
),
106+
},
107+
)),
108+
),
109+
),
105110
),
106111
],
107112
body: Stack(
108113
children: [
109114
if (updating != null)
110115
headers != null && headers.isNotEmpty
111116
? ClassList(
112-
classes: headers,
113-
sectioned: false,
114-
onTap: (classHeader) => Navigator.of(context).push(
115-
MaterialPageRoute<ChangeNotifierProvider>(
116-
builder: (context) => ChangeNotifierProvider.value(
117-
value: classProvider,
118-
child: ClassView(
119-
classHeader: classHeader,
117+
classes: headers,
118+
sectioned: false,
119+
onTap: (classHeader) =>
120+
Navigator.of(context).push(
121+
MaterialPageRoute<ChangeNotifierProvider>(
122+
builder: (context) =>
123+
ChangeNotifierProvider.value(
124+
value: classProvider,
125+
child: ClassView(
126+
classHeader: classHeader,
127+
),
120128
),
121-
),
122-
),
123129
),
124-
)
130+
),
131+
)
125132
: ErrorPage(
126-
errorMessage: S.current.messageNoClassesYet,
127-
imgPath: 'assets/illustrations/undraw_empty.png',
128-
info: [
129-
TextSpan(
130-
text: '${S.current.messageGetStartedByPressing} '),
131-
WidgetSpan(
132-
alignment: PlaceholderAlignment.middle,
133-
child: Icon(
134-
Icons.edit_outlined,
135-
size:
136-
Theme.of(context).textTheme.subtitle1.fontSize +
137-
2,
138-
),
139-
),
140-
TextSpan(text: ' ${S.current.messageButtonAbove}.'),
141-
]),
133+
errorMessage: S.current.messageNoClassesYet,
134+
imgPath: 'assets/illustrations/undraw_empty.png',
135+
info: [
136+
TextSpan(
137+
text: '${S.current.messageGetStartedByPressing} '),
138+
WidgetSpan(
139+
alignment: PlaceholderAlignment.middle,
140+
child: Icon(
141+
Icons.edit_outlined,
142+
size:
143+
Theme
144+
.of(context)
145+
.textTheme
146+
.subtitle1
147+
.fontSize +
148+
2,
149+
),
150+
),
151+
TextSpan(text: ' ${S.current.messageButtonAbove}.'),
152+
]),
142153
if (updating == null)
143154
const Center(child: CircularProgressIndicator()),
144155
if (updating == true)
145156
Container(
146-
color: Theme.of(context).disabledColor,
157+
color: Theme
158+
.of(context)
159+
.disabledColor,
147160
child: const Center(child: CircularProgressIndicator())),
148161
],
149162
),
@@ -210,13 +223,12 @@ class _AddClassesPageState extends State<AddClassesPage> {
210223
}
211224

212225
class ClassList extends StatefulWidget {
213-
ClassList(
214-
{this.classes,
215-
void Function(bool, String) onSelected,
216-
Set<String> initiallySelected,
217-
this.selectable = false,
218-
this.sectioned = true,
219-
void Function(ClassHeader) onTap})
226+
ClassList({this.classes,
227+
void Function(bool, String) onSelected,
228+
Set<String> initiallySelected,
229+
this.selectable = false,
230+
this.sectioned = true,
231+
void Function(ClassHeader) onTap})
220232
: onSelected = onSelected ?? ((selected, classId) {}),
221233
onTap = onTap ?? ((_) {}),
222234
initiallySelected = initiallySelected ?? {};
@@ -244,8 +256,8 @@ class _ClassListState extends State<ClassList> {
244256
String sectionName(BuildContext context, String year, String semester) =>
245257
'${S.current.labelYear} $year, ${S.current.labelSemester} $semester';
246258

247-
Map<String, dynamic> classesBySection(
248-
Set<ClassHeader> classes, BuildContext context) {
259+
Map<String, dynamic> classesBySection(Set<ClassHeader> classes,
260+
BuildContext context) {
249261
final map = <String, dynamic>{};
250262

251263
for (final c in classes) {
@@ -279,8 +291,8 @@ class _ClassListState extends State<ClassList> {
279291
children.addAll(values.map<Widget>(buildClassItem));
280292
expanded = values.fold(
281293
false,
282-
(dynamic selected, ClassHeader header) =>
283-
selected || widget.initiallySelected.contains(header.id));
294+
(dynamic selected, ClassHeader header) =>
295+
selected || widget.initiallySelected.contains(header.id));
284296
} else {
285297
final s = buildSections(context, sections[section], level: level + 1);
286298
expanded = expanded || s.containsSelected;
@@ -302,7 +314,8 @@ class _ClassListState extends State<ClassList> {
302314
return _Section(widgets: children, containsSelected: expanded);
303315
}
304316

305-
Widget buildClassItem(ClassHeader header) => Column(
317+
Widget buildClassItem(ClassHeader header) =>
318+
Column(
306319
children: [
307320
ClassListItem(
308321
selectable: widget.selectable,
@@ -334,16 +347,19 @@ class _ClassListState extends State<ClassList> {
334347
child: IconText(
335348
icon: Icons.info_outlined,
336349
text: '${S.current.infoSelect} ${S.current.infoClasses}.',
337-
style: Theme.of(context).textTheme.bodyText1,
350+
style: Theme
351+
.of(context)
352+
.textTheme
353+
.bodyText1,
338354
),
339355
),
340356
Padding(
341357
padding: const EdgeInsets.all(10),
342358
child: Column(
343359
children: widget.sectioned
344360
? (buildSections(
345-
context, classesBySection(widget.classes, context)))
346-
.widgets
361+
context, classesBySection(widget.classes, context)))
362+
.widgets
347363
: widget.classes.map(buildClassItem).toList()),
348364
),
349365
],
@@ -371,7 +387,8 @@ class ClassListItem extends StatefulWidget {
371387
this.selectable = false,
372388
void Function() onTap,
373389
this.hint,
374-
}) : onSelected = onSelected ?? ((_) {}),
390+
})
391+
: onSelected = onSelected ?? ((_) {}),
375392
onTap = onTap ?? (() {}),
376393
super(key: key);
377394

@@ -408,24 +425,32 @@ class _ClassListItemState extends State<ClassListItem> {
408425
widget.classHeader.name,
409426
style: widget.selectable
410427
? (selected
411-
? Theme.of(context)
412-
.textTheme
413-
.subtitle1
414-
.copyWith(fontWeight: FontWeight.bold)
415-
: Theme.of(context)
416-
.textTheme
417-
.subtitle1
418-
.copyWith(color: Theme.of(context).disabledColor))
419-
: Theme.of(context).textTheme.subtitle1,
428+
? Theme
429+
.of(context)
430+
.textTheme
431+
.subtitle1
432+
.copyWith(fontWeight: FontWeight.bold)
433+
: Theme
434+
.of(context)
435+
.textTheme
436+
.subtitle1
437+
.copyWith(color: Theme
438+
.of(context)
439+
.disabledColor))
440+
: Theme
441+
.of(context)
442+
.textTheme
443+
.subtitle1,
420444
),
421445
subtitle: widget.hint != null ? Text(widget.hint) : null,
422-
onTap: () => setState(() {
423-
if (widget.selectable) {
424-
selected = !selected;
425-
widget.onSelected(selected);
426-
}
427-
widget.onTap();
428-
}),
446+
onTap: () =>
447+
setState(() {
448+
if (widget.selectable) {
449+
selected = !selected;
450+
widget.onSelected(selected);
451+
}
452+
widget.onTap();
453+
}),
429454
);
430455
}
431456
}

lib/pages/home/home_page.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import 'package:acs_upb_mobile/pages/home/upcoming_events_card.dart';
21
import 'package:flutter/cupertino.dart';
32
import 'package:flutter/material.dart';
43
import 'package:provider/provider.dart';
54

65
import '../../authentication/service/auth_provider.dart';
76
import '../../generated/l10n.dart';
87
import '../../navigation/routes.dart';
9-
import '../../resources/remote_config.dart';
8+
import '../../resources/utils.dart';
109
import '../../widgets/scaffold.dart';
1110
import 'faq_card.dart';
1211
import 'favourite_websites_card.dart';
1312
import 'feedback_nudge.dart';
1413
import 'news_feed_card.dart';
1514
import 'profile_card.dart';
15+
import 'upcoming_events_card.dart';
1616

1717
class HomePage extends StatelessWidget {
1818
const HomePage({this.tabController, Key key}) : super(key: key);
@@ -36,7 +36,7 @@ class HomePage extends StatelessWidget {
3636
children: [
3737
if (authProvider.isAuthenticated) ProfileCard(),
3838
if (authProvider.isAuthenticated && !authProvider.isAnonymous
39-
&& RemoteConfigService.feedbackEnabled
39+
&& Utils.feedbackEnabled
4040
)
4141
FeedbackNudge(),
4242
if (authProvider.isAuthenticated && !authProvider.isAnonymous)

lib/resources/remote_config.dart

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ class RemoteConfigService {
1414
: _remoteConfig?.getBool(_feedbackEnabled) ?? defaults[_feedbackEnabled];
1515

1616
static Future<dynamic> initialize() async {
17-
// try {
17+
try {
1818
_remoteConfig = RemoteConfig.instance;
1919
await _remoteConfig.setDefaults(defaults);
2020
await _remoteConfig.fetchAndActivate();
21-
// } catch (e) {
22-
// print(
23-
// 'Unable to fetch remote config. Cached or default values will be used.');
24-
// }
25-
26-
// ? debug
21+
} catch (e) {
22+
print(
23+
'Unable to fetch remote config. Cached or default values will be used.');
24+
}
25+
// Does not work on web
2726
}
2827
}

0 commit comments

Comments
 (0)