Skip to content

Commit 42891f3

Browse files
committed
Add notifications screen
1 parent 6283af3 commit 42891f3

4 files changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:threebotlogin/app.dart';
3+
import 'package:threebotlogin/apps/farmers/farmers_user_data.dart';
4+
import 'package:threebotlogin/events/events.dart';
5+
import 'package:threebotlogin/events/go_home_event.dart';
6+
import 'package:threebotlogin/screens/notifications_screen.dart';
7+
8+
class Notifications implements App {
9+
static final Notifications _singleton = Notifications._internal();
10+
static const Widget _notificationsWidget = NotificationsScreen();
11+
12+
factory Notifications() {
13+
return _singleton;
14+
}
15+
16+
Notifications._internal();
17+
18+
@override
19+
Future<Widget> widget() async {
20+
return _notificationsWidget;
21+
}
22+
23+
@override
24+
void clearData() {
25+
clearAllData();
26+
}
27+
28+
@override
29+
bool emailVerificationRequired() {
30+
return true;
31+
}
32+
33+
@override
34+
bool pinRequired() {
35+
return true;
36+
}
37+
38+
@override
39+
void back() {
40+
Events().emit(GoHomeEvent());
41+
}
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'package:shared_preferences/shared_preferences.dart';
2+
3+
4+
Future<List<String>?> getNotificationSettings() async {
5+
final prefs = await SharedPreferences.getInstance();
6+
var notifications = prefs.getStringList('notifications');
7+
return notifications;
8+
}

app/lib/jrouter.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:threebotlogin/app.dart';
33
import 'package:threebotlogin/apps/council/council.dart';
44
import 'package:threebotlogin/apps/dao/dao.dart';
5+
import 'package:threebotlogin/apps/notifications/notifications.dart';
56
import 'package:threebotlogin/apps/wallet/wallet.dart';
67
import 'package:threebotlogin/screens/identity_verification_screen.dart';
78
import 'package:threebotlogin/screens/preference_screen.dart';
@@ -87,6 +88,14 @@ class JRouter {
8788
view: await Council().widget(),
8889
),
8990
app: Dao()),
91+
AppInfo(
92+
route: Route(
93+
path: '/notifications',
94+
name: 'Notifications',
95+
icon: Icons.how_to_vote_outlined,
96+
view: await Notifications().widget(),
97+
),
98+
app: null),
9099
AppInfo(
91100
route: Route(
92101
path: '/sign',
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:shared_preferences/shared_preferences.dart';
3+
4+
class NotificationsScreen extends StatefulWidget {
5+
const NotificationsScreen({super.key});
6+
7+
@override
8+
_NotificationsScreenState createState() => _NotificationsScreenState();
9+
}
10+
11+
class _NotificationsScreenState extends State<NotificationsScreen> {
12+
bool _notificationsEnabled = true;
13+
14+
static const String _notificationsEnabledKey = 'notificationsEnabled';
15+
16+
@override
17+
void initState() {
18+
super.initState();
19+
_loadNotificationPreference();
20+
}
21+
22+
void _loadNotificationPreference() async {
23+
final prefs = await SharedPreferences.getInstance();
24+
setState(() {
25+
_notificationsEnabled = prefs.getBool(_notificationsEnabledKey) ?? true;
26+
});
27+
}
28+
29+
void _saveNotificationPreference(bool newValue) async {
30+
final prefs = await SharedPreferences.getInstance();
31+
await prefs.setBool(_notificationsEnabledKey, newValue);
32+
}
33+
34+
@override
35+
Widget build(BuildContext context) {
36+
return Padding(
37+
padding: const EdgeInsets.symmetric(vertical: 16.0),
38+
child: Column(
39+
mainAxisAlignment: MainAxisAlignment.start,
40+
crossAxisAlignment:
41+
CrossAxisAlignment.stretch,
42+
children: <Widget>[
43+
SwitchListTile(
44+
title: const Text('Enable Push Notifications'),
45+
value: _notificationsEnabled,
46+
onChanged: (bool newValue) {
47+
setState(() {
48+
_notificationsEnabled = newValue;
49+
});
50+
_saveNotificationPreference(newValue);
51+
52+
if (newValue) {
53+
print('Notifications enabled. Implement subscription logic.');
54+
} else {
55+
print('Notifications disabled. Implement unsubscription logic.');
56+
}
57+
},
58+
secondary: const Icon(Icons.notifications),
59+
),
60+
],
61+
),
62+
);
63+
}
64+
}

0 commit comments

Comments
 (0)