Browse Source

fixed DB wiring, added graph display

main
root 4 months ago
parent
commit
7e7cc0b633
  1. 2
      .flutter-plugins-dependencies
  2. 6
      .packages
  3. 46
      lib/fragments/LoadingPage.dart
  4. 8
      lib/main.dart
  5. 86
      lib/pages/MoodDump.dart
  6. 5
      lib/pages/MoodForm.dart
  7. 7
      lib/providers/db.dart
  8. 2
      pubspec.yaml

2
.flutter-plugins-dependencies

@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"sqflite","path":"/home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/","dependencies":[]}],"android":[{"name":"sqflite","path":"/home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/","dependencies":[]}],"macos":[{"name":"sqflite","path":"/home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"sqflite","dependencies":[]}],"date_created":"2021-08-13 00:25:24.249587","version":"2.2.3"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"sqflite","path":"/home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/","dependencies":[]}],"android":[{"name":"sqflite","path":"/home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/","dependencies":[]}],"macos":[{"name":"sqflite","path":"/home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"sqflite","dependencies":[]}],"date_created":"2021-08-13 14:48:49.474530","version":"2.2.3"}

6
.packages

@ -3,7 +3,7 @@
#
# For more info see: https://dart.dev/go/dot-packages-deprecation
#
# Generated by pub on 2021-08-12 22:07:47.580095.
# Generated by pub on 2021-08-13 14:48:48.621057.
_fe_analyzer_shared:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-22.0.0/lib/
analyzer:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.1/lib/
args:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/args-2.2.0/lib/
@ -27,7 +27,6 @@ collection:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartla
convert:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/convert-3.0.1/lib/
crypto:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-3.0.1/lib/
dart_style:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/dart_style-2.0.3/lib/
equatable:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/equatable-2.0.3/lib/
fake_async:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/fake_async-1.2.0/lib/
ffi:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/
file:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/file-6.1.2/lib/
@ -44,6 +43,7 @@ glob:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org
graphs:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/graphs-2.0.0/lib/
http_multi_server:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/http_multi_server-3.0.1/lib/
http_parser:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-4.0.0/lib/
intl:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/intl-0.17.0/lib/
io:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/io-1.0.3/lib/
js:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.3/lib/
json_annotation:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/json_annotation-4.0.1/lib/
@ -72,6 +72,8 @@ state_notifier:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.da
stream_channel:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-2.1.0/lib/
stream_transform:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/stream_transform-2.0.0/lib/
string_scanner:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.1.0/lib/
syncfusion_flutter_charts:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_charts-19.2.55+1/lib/
syncfusion_flutter_core:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_core-19.2.55/lib/
synchronized:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/synchronized-3.0.0/lib/
term_glyph:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.2.0/lib/
test_api:file:///home/diane/dev/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/test_api-0.3.0/lib/

46
lib/fragments/LoadingPage.dart

@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class LoadingPage extends StatelessWidget {
const LoadingPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
child: CircularProgressIndicator(),
width: 60,
height: 60,
),
],
),
);
}
class LoadingErrorPage extends StatelessWidget {
const LoadingErrorPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Icon(Icons.error_outline),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('Loading failed'),
),
],
),
);
}
Widget loading<T>(AsyncValue<T> v, Widget Function(T value) data) => v.when(
data: data,
loading: () => const LoadingPage(),
error: (mds, _) => const LoadingErrorPage(),
);

8
lib/main.dart

@ -14,11 +14,11 @@ class MoodDroid extends StatelessWidget {
return MaterialApp(
title: AppTitle,
theme: AppTheme,
initialRoute: '/enter-mood/1',
initialRoute: 'mood-picker',
routes: {
'/': (context) => MoodDump(),
'/enter-mood/1': (context) => MoodPicker(),
'/enter-mood/2': (context) => MoodWriter(),
'dashboard': (context) => MoodDump(),
'mood-picker': (context) => MoodPicker(),
'mood-writer': (context) => MoodWriter(),
},
);
}

86
lib/pages/MoodDump.dart

@ -1,60 +1,70 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mood_droid/constants.dart';
import 'package:mood_droid/helpers/human-readable.dart';
import 'package:mood_droid/data/db.dart';
import 'package:mood_droid/data/mood.dart';
import 'package:mood_droid/fragments/LoadingPage.dart';
import 'package:mood_droid/providers/db.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class MoodDump extends ConsumerWidget {
@override
Widget build(BuildContext context, ScopedReader watch) {
final moods = watch(moodsProvider);
final $db = watch(DbProvider);
return Scaffold(
appBar: AppBar(
title: Text(AppTitle),
),
body: moods.when(
data: (mds) {
return ListView.builder(
itemCount: mds.length,
itemBuilder: (ctx, i) => ListTile(
title: Text(readableMood(mds[i].mood)),
),
);
},
loading: () {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
child: CircularProgressIndicator(),
width: 60,
height: 60,
),
],
),
);
},
error: (mds, _) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Icon(Icons.error_outline),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('Loading failed'),
body: loading<AppDatabase>(
$db,
(db) => FutureBuilder<List<Mood>>(
future: db.moodDao.findAllRecentMoods(),
initialData: [],
builder: (ctx, snap) {
final data = snap.data ?? [];
final now = DateTime.now();
return SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 16,
child: SfCartesianChart(
primaryXAxis: DateTimeAxis(
minimum: now.subtract(Duration(days: 7)),
maximum: now,
),
primaryYAxis: CategoryAxis(
minimum: MoodLevel.depressive.index.toDouble(),
maximum: MoodLevel.manic.index.toDouble(),
),
title: ChartTitle(text: 'This past week'),
series: [
LineSeries<Mood, DateTime>(
dataSource: data,
xValueMapper: (d, _) => d.snapshotDate,
yValueMapper: (d, _) => d.mood.index,
name: 'Mood',
)
],
)
)
],
),
],
),
);
// return ListView.builder(
// itemCount: data.length,
// itemBuilder: (ctx, i) => ListTile(
// title: Text(readableMood(data[i].mood)),
// ),
// );
},
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.refresh),
onPressed: () {
Navigator.of(context).pushReplacementNamed('/enter-mood/1');
Navigator.popAndPushNamed(context, 'mood-picker');
},
),
);

5
lib/pages/MoodForm.dart

@ -50,7 +50,7 @@ class MoodPickerState extends State<MoodPicker> {
onPressed: () {
Navigator.popAndPushNamed(
context,
'/enter-mood/2',
'mood-writer',
arguments: _mood,
);
},
@ -119,8 +119,7 @@ class MoodWriterState extends State<MoodWriter> {
mood,
_talk,
));
Navigator.of(context)
.pushNamedAndRemoveUntil('/', (route) => false);
Navigator.popAndPushNamed(context, 'dashboard');
});
},
child: Text(

7
lib/providers/db.dart

@ -3,10 +3,3 @@ import 'package:riverpod/riverpod.dart';
final DbProvider = FutureProvider<AppDatabase>(
(ref) => $FloorAppDatabase.databaseBuilder('app_database.db').build());
// ignore: top_level_function_literal_block
final moodsProvider = FutureProvider((ref) async {
final db = await ref.watch(DbProvider.future);
final moods = await db.moodDao.findAllRecentMoods();
return moods;
});

2
pubspec.yaml

@ -10,9 +10,9 @@ dependencies:
flutter:
sdk: flutter
floor: ^1.1.0
equatable: ^2.0.0
flutter_riverpod: ^0.14.0+3
riverpod: ^0.14.0+3
syncfusion_flutter_charts: ^19.2.55+1
dev_dependencies:
flutter_test: