Skip to content

Commit

Permalink
corrected notification logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Hareesh-Nandigrama committed Sep 9, 2023
1 parent 9c8f46f commit a928dbf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
31 changes: 28 additions & 3 deletions lib/pages/notifications/notification_settings.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:flutter/material.dart';
import 'package:onestop_dev/globals/database_strings.dart';
import 'package:onestop_dev/globals/my_colors.dart';
import 'package:onestop_dev/globals/my_fonts.dart';
import 'package:onestop_dev/services/api.dart';
import 'package:onestop_dev/stores/login_store.dart';
import 'package:onestop_dev/widgets/notifications/notif_toggle.dart';
import '../../globals/my_colors.dart';
import '../../globals/my_fonts.dart';


class NotificationSettings extends StatefulWidget {
const NotificationSettings({Key? key}) : super(key: key);
Expand All @@ -12,6 +15,8 @@ class NotificationSettings extends StatefulWidget {
}

class _NotificationSettingsState extends State<NotificationSettings> {
bool isLoading = false;

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -21,13 +26,33 @@ class _NotificationSettingsState extends State<NotificationSettings> {
style: MyFonts.w500,
),
),
body: ListView(
body: Column(
children: [
NotifToggle(text: NotificationCategories.cabSharing),
NotifToggle(text: NotificationCategories.lost),
NotifToggle(text: NotificationCategories.found),
NotifToggle(text: NotificationCategories.buy),
NotifToggle(text: NotificationCategories.sell),
ElevatedButton(onPressed: () async {
if(isLoading)
{
return;
}
setState(() {
isLoading = true;
});
try{
await APIService().updateUserNotifPref(LoginStore.userData['notifPref']);}
catch(e)
{
print(e);
}
setState(() {
isLoading = false;
});
}, child: isLoading? CircularProgressIndicator(
color: Colors.white,
) : Text('Save'))
],
),
);
Expand Down
13 changes: 3 additions & 10 deletions lib/widgets/notifications/notif_toggle.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

import 'package:flutter/material.dart';
import 'package:flutter_switch/flutter_switch.dart';
import 'package:get/get.dart';
import 'package:onestop_dev/functions/utility/capitalize_string.dart';
import 'package:onestop_dev/services/api.dart';
import 'package:onestop_dev/stores/login_store.dart';

import '../../globals/my_colors.dart';
import '../../globals/my_fonts.dart';

Expand All @@ -18,7 +15,6 @@ class NotifToggle extends StatefulWidget {
}

class _NotifToggleState extends State<NotifToggle> {
bool isLoading = false;
@override
Widget build(BuildContext context) {
var name = capitalize(widget.text);
Expand All @@ -36,13 +32,10 @@ class _NotifToggleState extends State<NotifToggle> {
height: 32,
width: 52,
value: LoginStore.userData['notifPref'][widget.text]!,
onToggle: (val) async {
if(isLoading) {return;}
isLoading = true;
onToggle: (val) {
LoginStore.userData['notifPref'][widget.text] = val;
await APIService().updateUserNotifPref(LoginStore.userData['notifPref']);
setState((){});
isLoading = false;
setState(() {
});
},
),
],
Expand Down

0 comments on commit a928dbf

Please sign in to comment.