This repository was archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.dart
96 lines (84 loc) · 2.86 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'ui/podcast_page.dart';
import 'ui/configuration.dart';
import 'ui/home_page.dart';
import 'ui/settings_page.dart';
import 'podcast_utils.dart';
final Logger log = new Logger('PodrickMain');
final String podcastPrefix = '/podcast:';
class PodrickApp extends StatefulWidget {
@override
_PodrickAppState createState() => new _PodrickAppState();
}
class _PodrickAppState extends State<PodrickApp> {
PodrickConfiguration _configuration = new PodrickConfiguration(
theme: PodrickTheme.dark,
debugShowGrid: false,
debugShowSizes: false,
debugShowBaselines: false,
debugShowLayers: false,
debugShowPointers: false,
debugShowRainbow: false,
showPerformanceOverlay: false,
showSemanticsDebugger: false);
@override
void initState() {
super.initState();
}
ThemeData get theme {
switch (_configuration.theme) {
case PodrickTheme.light:
return new ThemeData(
brightness: Brightness.light, primarySwatch: Colors.blue);
case PodrickTheme.dark:
return new ThemeData(
brightness: Brightness.dark, primarySwatch: Colors.lightBlue);
}
assert(_configuration.theme != null);
return null;
}
Route<Null> _getRoute(RouteSettings settings) {
log.info("Routing request ${settings.name}.");
// Paths *must* start with a '/'.
if (settings.name[0] != '/') {
return null;
}
// Specific channel page.
if (settings.name.startsWith(podcastPrefix)) {
final String podcastKeyString = settings.name.substring(podcastPrefix.length);
final PodcastKey podcastKey = new PodcastKey(podcastKeyString);
log.info("Routing request for podcast ${podcastKey.key} -> ${podcastKey.getRssUrl()}.");
return new MaterialPageRoute<Null>(
settings: settings,
builder: (BuildContext context) => new PodcastPage(podcastKey));
} else {
log.warning("Could not handle route ${settings.name}.");
}
// Other paths are defined in the routes table.
return null;
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Podrick',
theme: theme,
debugShowMaterialGrid: _configuration.debugShowGrid,
showPerformanceOverlay: _configuration.showPerformanceOverlay,
showSemanticsDebugger: _configuration.showSemanticsDebugger,
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => new PodrickHomePage(title: 'Podrick'),
'/settings': (BuildContext context) => new PodrickSettingsPage()
},
onGenerateRoute: _getRoute,
);
}
}
void main() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
});
log.info("Starting Podrick.");
runApp(new PodrickApp());
}