Skip to content

Commit 3cbc295

Browse files
fixed error when token is valid but has 0 notifications
1 parent 4335d0e commit 3cbc295

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

lib/pages/homepage.dart

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class _HomePageState extends State<HomePage> {
3232
List<dynamic> _notifications = [];
3333

3434
_checkIfSetupDone() async {
35-
flutterLocalNotificationsPlugin =
36-
FlutterLocalNotificationsPlugin();
35+
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
3736
if (await storage.read(key: "setup") != "done") {
3837
await _showInfoDialogBox();
3938
bool result = await _getNotificationPermission();
@@ -85,8 +84,10 @@ class _HomePageState extends State<HomePage> {
8584
setState(() {
8685
_notifications = result;
8786
});
88-
String lastnotification = _notifications[0]['subject']['title'];
89-
storage.write(key: 'lastnotification', value: lastnotification);
87+
if (_notifications.isNotEmpty) {
88+
String lastnotification = _notifications[0]['subject']['title'];
89+
storage.write(key: 'lastnotification', value: lastnotification);
90+
}
9091
} catch (_) {
9192
_showError();
9293
}
@@ -104,7 +105,10 @@ class _HomePageState extends State<HomePage> {
104105
Navigator.push(
105106
context,
106107
MaterialPageRoute(
107-
builder: (context) => SettingsPage(storage: storage, github: github,)));
108+
builder: (context) => SettingsPage(
109+
storage: storage,
110+
github: github,
111+
)));
108112
}
109113

110114
@override
@@ -126,11 +130,11 @@ class _HomePageState extends State<HomePage> {
126130
foregroundColor: Colors.white,
127131
title: const Text('GitAlerts'),
128132
actions: [
129-
IconButton(
130-
icon: const Icon(Icons.settings),
131-
onPressed: () => _goToSettingsPage(),
132-
),
133-
],
133+
IconButton(
134+
icon: const Icon(Icons.settings),
135+
onPressed: () => _goToSettingsPage(),
136+
),
137+
],
134138
),
135139
backgroundColor: Colors.grey,
136140
body: RefreshIndicator(
@@ -149,7 +153,7 @@ class _HomePageState extends State<HomePage> {
149153
final notification = _notifications[index];
150154
final repoFullName = notification['repository']['full_name'];
151155
final notificationText = notification['subject']['title'];
152-
156+
153157
return Card(
154158
margin: const EdgeInsets.all(6.0),
155159
child: Column(
@@ -159,13 +163,19 @@ class _HomePageState extends State<HomePage> {
159163
padding: const EdgeInsets.all(9.0),
160164
child: Text(
161165
repoFullName,
162-
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0,),
166+
style: const TextStyle(
167+
fontWeight: FontWeight.bold,
168+
fontSize: 18.0,
169+
),
163170
),
164171
),
165172
Padding(
166173
padding: const EdgeInsets.all(18.0),
167-
child: Text(notificationText,
168-
style: const TextStyle(fontSize: 16.0,),
174+
child: Text(
175+
notificationText,
176+
style: const TextStyle(
177+
fontSize: 16.0,
178+
),
169179
),
170180
),
171181
],

0 commit comments

Comments
 (0)