-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from K-w-e/feature/notification_system
WIP notifications system
- Loading branch information
Showing
8 changed files
with
260 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; | ||
import 'package:permission_handler/permission_handler.dart'; | ||
|
||
final FlutterLocalNotificationsPlugin notificationsPlugin = FlutterLocalNotificationsPlugin(); | ||
|
||
const AndroidNotificationChannel channel = AndroidNotificationChannel( | ||
'sossoldi#reminder', // id del canale | ||
'Reminder', // nome del canale | ||
importance: Importance.high, | ||
); | ||
|
||
void initializeNotifications() async { | ||
var initializationSettingsAndroid = const AndroidInitializationSettings('@mipmap/ic_launcher'); | ||
var initializationSettingsIOS = const DarwinInitializationSettings(); | ||
var initializationSettings = InitializationSettings(android: initializationSettingsAndroid, iOS: initializationSettingsIOS); | ||
notificationsPlugin.initialize(initializationSettings); | ||
await notificationsPlugin.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()?.createNotificationChannel(channel); | ||
} | ||
|
||
void requestNotificationPermissions() async { | ||
await Permission.notification.request(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
import '../../../providers/settings_provider.dart'; | ||
|
||
class NotificationTypeTile extends ConsumerStatefulWidget { | ||
final NotificationReminderType type; | ||
final VoidCallback setNotificationTypeCallback; | ||
|
||
const NotificationTypeTile( | ||
{Key? key, required this.type, required this.setNotificationTypeCallback}) | ||
: super(key: key); | ||
|
||
@override | ||
_NotificationTypeTileState createState() => _NotificationTypeTileState(); | ||
} | ||
|
||
class _NotificationTypeTileState extends ConsumerState<NotificationTypeTile> { | ||
late SharedPreferences prefs; | ||
bool isPrefInizialized = false; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
initPrefs(); | ||
} | ||
|
||
Future<void> initPrefs() async { | ||
prefs = await SharedPreferences.getInstance(); | ||
setState(() { | ||
isPrefInizialized = true; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (!isPrefInizialized) return Container(); | ||
|
||
NotificationReminderType? notificationReminderType = | ||
NotificationReminderType?.values?.firstWhere((e) => | ||
e.toString().split('.').last == | ||
prefs.getString('transaction-reminder-cadence')); | ||
|
||
final typeName = | ||
"${widget.type.name[0].toUpperCase()}${widget.type.name.substring(1).toLowerCase()}"; | ||
|
||
return GestureDetector( | ||
onTap: () { | ||
widget.setNotificationTypeCallback.call(); | ||
}, | ||
child: Container( | ||
margin: const EdgeInsets.symmetric(horizontal: 15, vertical: 5), | ||
width: MediaQuery.of(context).size.width, | ||
height: 40, | ||
decoration: BoxDecoration( | ||
border: Border.all( | ||
color: notificationReminderType == widget.type | ||
? Colors.blue | ||
: Colors.grey, | ||
), | ||
borderRadius: BorderRadius.circular(4.0), | ||
), | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Row( | ||
children: [ | ||
Text( | ||
typeName, | ||
style: TextStyle( | ||
color: notificationReminderType == widget.type | ||
? Colors.blue | ||
: Colors.black, | ||
), | ||
), | ||
const Spacer(), | ||
notificationReminderType == widget.type | ||
? const Icon( | ||
Icons.check, | ||
color: Colors.blue, | ||
) | ||
: Container() | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.