Skip to content

Commit a108293

Browse files
tt-kevinchangclaude
andcommitted
Add bot watching, light/dark mode, and request timeouts
- Watch bot accounts (added by login on the Members page) and limit bot PRs to selected repositories - Add a light/dark mode toggle, saved across sessions - Time out stalled GitHub requests after 30 seconds; retry failed refreshes sooner and pause auto-refresh after 3 network failures - Remove GitHub debug logging - Use semantic labels instead of tooltips on member icons (flutter/flutter#182444) - Bump http to ^1.5.0 and exclude platform/build folders from analysis Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e743a20 commit a108293

16 files changed

Lines changed: 754 additions & 158 deletions

‎analysis_options.yaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
# The following line activates a set of recommended lints for Flutter apps,
99
# packages, and plugins designed to encourage good coding practices.
10+
analyzer:
11+
exclude:
12+
- build/**
13+
- android/**
14+
- ios/**
15+
- web/**
16+
- windows/**
17+
- macos/**
18+
- linux/**
1019
include: package:flutter_lints/flutter.yaml
1120

1221
linter:

‎lib/app_theme.dart‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import 'package:flutter/material.dart';
2+
3+
// Colors that change between dark and light mode.
4+
class AppColors extends ThemeExtension<AppColors> {
5+
const AppColors({
6+
required this.text,
7+
required this.secondaryText,
8+
required this.mutedText,
9+
required this.headerBand,
10+
});
11+
12+
final Color text;
13+
final Color secondaryText;
14+
final Color mutedText;
15+
final Color headerBand;
16+
17+
static const dark = AppColors(
18+
text: Colors.white,
19+
secondaryText: Colors.white60,
20+
mutedText: Colors.white54,
21+
headerBand: Colors.white10,
22+
);
23+
24+
static const light = AppColors(
25+
text: Colors.black,
26+
secondaryText: Colors.black54,
27+
mutedText: Colors.black45,
28+
headerBand: Colors.white54,
29+
);
30+
31+
static AppColors of(BuildContext context) =>
32+
Theme.of(context).extension<AppColors>()!;
33+
34+
@override
35+
AppColors copyWith({
36+
Color? text,
37+
Color? secondaryText,
38+
Color? mutedText,
39+
Color? headerBand,
40+
}) {
41+
return AppColors(
42+
text: text ?? this.text,
43+
secondaryText: secondaryText ?? this.secondaryText,
44+
mutedText: mutedText ?? this.mutedText,
45+
headerBand: headerBand ?? this.headerBand,
46+
);
47+
}
48+
49+
@override
50+
AppColors lerp(AppColors? other, double t) {
51+
if (other == null) return this;
52+
return AppColors(
53+
text: Color.lerp(text, other.text, t)!,
54+
secondaryText: Color.lerp(secondaryText, other.secondaryText, t)!,
55+
mutedText: Color.lerp(mutedText, other.mutedText, t)!,
56+
headerBand: Color.lerp(headerBand, other.headerBand, t)!,
57+
);
58+
}
59+
}
60+
61+
final darkTheme = _buildTheme(dark: true);
62+
final lightTheme = _buildTheme(dark: false);
63+
64+
ThemeData _buildTheme({required bool dark}) {
65+
final colorScheme = ColorScheme.fromSeed(
66+
seedColor: Colors.blue.shade900,
67+
surface: dark ? const Color(0xFF505050) : null,
68+
);
69+
return ThemeData(
70+
colorScheme: colorScheme,
71+
useMaterial3: true,
72+
scaffoldBackgroundColor:
73+
dark ? colorScheme.surface : colorScheme.surfaceDim,
74+
extensions: [dark ? AppColors.dark : AppColors.light],
75+
);
76+
}

‎lib/configure_state.dart‎

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:convert';
22

33
import 'package:flutter/material.dart';
44
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
5+
import 'package:pr_watch/app_theme.dart';
56
import 'package:pr_watch/models/app_state.dart';
67
import 'package:pr_watch/models/organization.dart';
78
import 'package:pr_watch/models/settings.dart';
@@ -119,6 +120,33 @@ class _ConfigureStateState extends State<ConfigureState> {
119120
value: _appState.members.map((e) => e.id).join(','));
120121
}
121122

123+
// Bots can't be team members, so they're saved by login from the
124+
// Members page. Their watched state is kept with the members'.
125+
var botLogins = await storage.read(key: 'BOTS');
126+
if (botLogins != null && botLogins.isNotEmpty) {
127+
var watched = (await storage.read(key: 'WATCHED_MEMBERS'))
128+
?.split(',')
129+
.map((e) => int.tryParse(e));
130+
for (var login in botLogins.split(',')) {
131+
try {
132+
var bot = await GithubService.instance.fetchMember(login);
133+
_appState.bots.add(bot);
134+
_appState.isMemberWatched[bot.id] =
135+
watched?.contains(bot.id) ?? true;
136+
} on Exception catch (e) {
137+
if (mounted) SnackbarService.show(context, e.toString());
138+
}
139+
}
140+
}
141+
142+
// No saved selection means bot PRs show from every team repository.
143+
var botRepos = await storage.read(key: 'BOT_REPOS');
144+
var botRepoIds = botRepos?.split(',').map((e) => int.tryParse(e));
145+
for (var i = 0; i < _appState.repositories.length; i++) {
146+
_appState.isBotRepoWatched[_appState.repositories[i].id] =
147+
botRepoIds?.contains(_appState.repositories[i].id) ?? true;
148+
}
149+
122150
var adminReviewers = await storage.read(key: 'ADMIN_REVIEWER');
123151
if (adminReviewers != null) {
124152
var admin = adminReviewers.split(',').map((e) => int.tryParse(e));
@@ -209,13 +237,14 @@ class _ConfigureStateState extends State<ConfigureState> {
209237
}
210238

211239
Widget _buildOrgSelect() {
240+
final colors = AppColors.of(context);
212241
return Column(
213242
children: [
214-
const Padding(
215-
padding: EdgeInsets.all(16.0),
243+
Padding(
244+
padding: const EdgeInsets.all(16.0),
216245
child: Text(
217246
'Select an organization',
218-
style: TextStyle(fontSize: 36, color: Colors.white),
247+
style: TextStyle(fontSize: 36, color: colors.text),
219248
),
220249
),
221250
const Divider(
@@ -252,37 +281,38 @@ class _ConfigureStateState extends State<ConfigureState> {
252281
),
253282
),
254283
if (_orgs.isEmpty)
255-
const Center(
284+
Center(
256285
child: Text('You are not part of any organizations',
257-
style: TextStyle(fontSize: 24, color: Colors.white)),
286+
style: TextStyle(fontSize: 24, color: colors.text)),
258287
),
259288
],
260289
);
261290
}
262291

263292
Widget _buildTeamSelect() {
293+
final colors = AppColors.of(context);
264294
return Column(
265295
children: [
266-
const Padding(
267-
padding: EdgeInsets.all(16.0),
296+
Padding(
297+
padding: const EdgeInsets.all(16.0),
268298
child: Text(
269299
'Select a team',
270-
style: TextStyle(fontSize: 36, color: Colors.white),
300+
style: TextStyle(fontSize: 36, color: colors.text),
271301
),
272302
),
273303
TextField(
274-
decoration: const InputDecoration(
304+
decoration: InputDecoration(
275305
labelText: 'Search',
276-
labelStyle: TextStyle(color: Colors.white),
277-
prefixIcon: Icon(Icons.search, color: Colors.white),
306+
labelStyle: TextStyle(color: colors.text),
307+
prefixIcon: Icon(Icons.search, color: colors.text),
278308
enabledBorder: UnderlineInputBorder(
279-
borderSide: BorderSide(color: Colors.white),
309+
borderSide: BorderSide(color: colors.text),
280310
),
281311
focusedBorder: UnderlineInputBorder(
282-
borderSide: BorderSide(color: Colors.white),
312+
borderSide: BorderSide(color: colors.text),
283313
),
284314
),
285-
style: const TextStyle(color: Colors.white),
315+
style: TextStyle(color: colors.text),
286316
onChanged: (value) {
287317
setState(() {
288318
_emptySearchText = value.isEmpty;
@@ -335,14 +365,14 @@ class _ConfigureStateState extends State<ConfigureState> {
335365
),
336366
),
337367
if (_filteredTeams.isEmpty && !_emptySearchText)
338-
const Center(
368+
Center(
339369
child: Text('No teams found',
340-
style: TextStyle(fontSize: 24, color: Colors.white)),
370+
style: TextStyle(fontSize: 24, color: colors.text)),
341371
),
342372
if (_filteredTeams.isEmpty && _emptySearchText)
343-
const Center(
373+
Center(
344374
child: Text('Search for your team',
345-
style: TextStyle(fontSize: 24, color: Colors.white)),
375+
style: TextStyle(fontSize: 24, color: colors.text)),
346376
),
347377
],
348378
);
@@ -359,7 +389,8 @@ class _ConfigureStateState extends State<ConfigureState> {
359389
const SizedBox(height: 10),
360390
Text(
361391
_loadingText,
362-
style: const TextStyle(color: Colors.white, fontSize: 24),
392+
style: TextStyle(
393+
color: AppColors.of(context).text, fontSize: 24),
363394
),
364395
],
365396
))

‎lib/empty_state.dart‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:pr_watch/app_theme.dart';
23
import 'package:url_launcher/url_launcher.dart';
34

45
class EmptyState extends StatefulWidget {
@@ -18,15 +19,16 @@ class _EmptyStateState extends State<EmptyState> {
1819

1920
@override
2021
Widget build(BuildContext context) {
22+
final colors = AppColors.of(context);
2123
return Center(
2224
child: IntrinsicWidth(
2325
child: Column(
2426
mainAxisAlignment: MainAxisAlignment.center,
2527
children: [
26-
const Text('Please enter a github token from',
28+
Text('Please enter a github token from',
2729
style: TextStyle(
2830
fontSize: 20,
29-
color: Colors.white,
31+
color: colors.text,
3032
)),
3133
InkWell(
3234
onTap: () =>
@@ -44,18 +46,18 @@ class _EmptyStateState extends State<EmptyState> {
4446
Flexible(
4547
child: TextField(
4648
controller: controller,
47-
decoration: const InputDecoration(
49+
decoration: InputDecoration(
4850
labelText: 'GITHUB_TOKEN',
49-
labelStyle: TextStyle(color: Colors.white),
50-
border: OutlineInputBorder(),
51-
constraints: BoxConstraints(minWidth: 200),
51+
labelStyle: TextStyle(color: colors.text),
52+
border: const OutlineInputBorder(),
53+
constraints: const BoxConstraints(minWidth: 200),
5254
),
53-
style: const TextStyle(color: Colors.white),
55+
style: TextStyle(color: colors.text),
5456
onSubmitted: setToken,
5557
),
5658
),
5759
IconButton(
58-
icon: const Icon(Icons.save, color: Colors.white),
60+
icon: Icon(Icons.save, color: colors.text),
5961
onPressed: () => setToken(controller.text),
6062
),
6163
],

‎lib/load_state.dart‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
3+
import 'package:pr_watch/app_theme.dart';
34
import 'package:pr_watch/models/app_state.dart';
45
import 'package:pr_watch/services/github_service.dart';
56
import 'package:pr_watch/services/snackbar_service.dart';
@@ -40,13 +41,14 @@ class _LoadStateState extends State<LoadState> {
4041

4142
@override
4243
Widget build(BuildContext context) {
43-
return const Center(
44+
return Center(
4445
child: Column(
4546
mainAxisAlignment: MainAxisAlignment.center,
4647
children: [
47-
CircularProgressIndicator(),
48-
SizedBox(height: 20),
49-
Text('Loading...'),
48+
const CircularProgressIndicator(),
49+
const SizedBox(height: 20),
50+
Text('Loading...',
51+
style: TextStyle(color: AppColors.of(context).text)),
5052
],
5153
),
5254
);

‎lib/main.dart‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import 'package:flutter/material.dart';
2+
import 'package:pr_watch/app_theme.dart';
23
import 'package:pr_watch/my_home_page.dart';
4+
import 'package:pr_watch/services/theme_service.dart';
35

4-
void main() {
6+
void main() async {
7+
WidgetsFlutterBinding.ensureInitialized();
8+
await ThemeService.instance.load();
59
runApp(const MyApp());
610
}
711

@@ -11,16 +15,15 @@ class MyApp extends StatelessWidget {
1115
// This widget is the root of your application.
1216
@override
1317
Widget build(BuildContext context) {
14-
return MaterialApp(
15-
title: 'Flutter Demo',
16-
theme: ThemeData(
17-
colorScheme: ColorScheme.fromSeed(
18-
seedColor: Colors.blue.shade900,
19-
surface: const Color(0xFF505050),
20-
),
21-
useMaterial3: true,
18+
return ValueListenableBuilder<ThemeMode>(
19+
valueListenable: ThemeService.instance,
20+
builder: (context, themeMode, _) => MaterialApp(
21+
title: 'Flutter Demo',
22+
theme: lightTheme,
23+
darkTheme: darkTheme,
24+
themeMode: themeMode,
25+
home: const MyHomePage(title: 'PR Watch'),
2226
),
23-
home: const MyHomePage(title: 'PR Watch'),
2427
);
2528
}
2629
}

0 commit comments

Comments
 (0)