diff options
| -rw-r--r-- | lib/home.dart | 3 | ||||
| -rw-r--r-- | lib/jotai.dart | 12 | ||||
| -rw-r--r-- | lib/settings.dart | 26 |
3 files changed, 39 insertions, 2 deletions
diff --git a/lib/home.dart b/lib/home.dart index b9dce40..2e04d25 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -48,8 +48,9 @@ class _HomePageState extends State<HomePage> { }); } }); - _positionStream?.onError((error) { + _positionStream?.onError((error, stack) { _positionStream?.cancel(); + logObservable.value = logObservable.value..add('$error\n$stack'); Timer(Duration(seconds: 1), () => _initPositionStream(locationAccuracy)); }); } diff --git a/lib/jotai.dart b/lib/jotai.dart index 5524e6a..dc1b165 100644 --- a/lib/jotai.dart +++ b/lib/jotai.dart @@ -41,7 +41,15 @@ Future<T> fromString<T>( .then( // Going through all of these sounds like it's slower than necessary, // but it's very simple, and most of the options lists are very small. - (value) => options.firstWhere((option) => value == toString(option)), + (value) { + try { + return options.firstWhere((option) => value == toString(option)); + } catch (error, stack) { + logObservable.value = logObservable.value + ..add('While loading $key:\n$error\n$stack'); + rethrow; + } + }, ); } @@ -82,6 +90,8 @@ final locationAccuracyObservable = observablePreference( LocationAccuracy.values, ); +final logObservable = Observable(<String>[]); + class Observable<T> { T _value; int _nextId = 0; diff --git a/lib/settings.dart b/lib/settings.dart index 71906b1..997e1a9 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -149,6 +149,25 @@ class SelectTile<T> extends StatelessWidget { } } +class LogPage extends StatelessWidget { + const LogPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text('Logs')), + body: ObserverBuilder( + observable: logObservable, + builder: (context, logs, _) => ListView.builder( + itemCount: logs.length, + itemBuilder: (context, index) => + Text(logs[index], style: TextStyle(fontFamily: 'RobotoMono')), + ), + ), + ); + } +} + class SettingsPage extends StatelessWidget { const SettingsPage({super.key}); @@ -244,6 +263,13 @@ class SettingsPage extends StatelessWidget { onChanged: (value) => setLocationAccuracy(value), ), ), + ListTile( + title: Text("View logs"), + onTap: () => Navigator.push( + context, + MaterialPageRoute(builder: (context) => LogPage()), + ), + ), Divider(), SectionHeader('About'), ListTile( |
