Skip to content

Commit

Permalink
fixed error when token is valid but has 0 notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
aldrinzigmundv committed Oct 12, 2023
1 parent 4335d0e commit 3cbc295
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions lib/pages/homepage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class _HomePageState extends State<HomePage> {
List<dynamic> _notifications = [];

_checkIfSetupDone() async {
flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
if (await storage.read(key: "setup") != "done") {
await _showInfoDialogBox();
bool result = await _getNotificationPermission();
Expand Down Expand Up @@ -85,8 +84,10 @@ class _HomePageState extends State<HomePage> {
setState(() {
_notifications = result;
});
String lastnotification = _notifications[0]['subject']['title'];
storage.write(key: 'lastnotification', value: lastnotification);
if (_notifications.isNotEmpty) {
String lastnotification = _notifications[0]['subject']['title'];
storage.write(key: 'lastnotification', value: lastnotification);
}
} catch (_) {
_showError();
}
Expand All @@ -104,7 +105,10 @@ class _HomePageState extends State<HomePage> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SettingsPage(storage: storage, github: github,)));
builder: (context) => SettingsPage(
storage: storage,
github: github,
)));
}

@override
Expand All @@ -126,11 +130,11 @@ class _HomePageState extends State<HomePage> {
foregroundColor: Colors.white,
title: const Text('GitAlerts'),
actions: [
IconButton(
icon: const Icon(Icons.settings),
onPressed: () => _goToSettingsPage(),
),
],
IconButton(
icon: const Icon(Icons.settings),
onPressed: () => _goToSettingsPage(),
),
],
),
backgroundColor: Colors.grey,
body: RefreshIndicator(
Expand All @@ -149,7 +153,7 @@ class _HomePageState extends State<HomePage> {
final notification = _notifications[index];
final repoFullName = notification['repository']['full_name'];
final notificationText = notification['subject']['title'];

return Card(
margin: const EdgeInsets.all(6.0),
child: Column(
Expand All @@ -159,13 +163,19 @@ class _HomePageState extends State<HomePage> {
padding: const EdgeInsets.all(9.0),
child: Text(
repoFullName,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0,),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
),
),
),
Padding(
padding: const EdgeInsets.all(18.0),
child: Text(notificationText,
style: const TextStyle(fontSize: 16.0,),
child: Text(
notificationText,
style: const TextStyle(
fontSize: 16.0,
),
),
),
],
Expand Down

0 comments on commit 3cbc295

Please sign in to comment.