Get alarm working
This commit is contained in:
+8
-3
@@ -1,10 +1,12 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fmassive/gym_set.dart';
|
||||
import 'package:fmassive/main.dart';
|
||||
import 'package:moor/ffi.dart';
|
||||
import 'package:moor/moor.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
import 'settings.dart';
|
||||
|
||||
part 'database.g.dart';
|
||||
@@ -20,6 +22,8 @@ class MyDatabase extends _$MyDatabase {
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
onCreate: (Migrator m) async {
|
||||
await m.createAll();
|
||||
var data = await db.select(db.settings).get();
|
||||
if (data.isEmpty) await db.into(db.settings).insert(defaultSettings);
|
||||
},
|
||||
onUpgrade: (Migrator m, int from, int to) async {
|
||||
// no migrations yet
|
||||
@@ -29,8 +33,9 @@ class MyDatabase extends _$MyDatabase {
|
||||
|
||||
LazyDatabase _openConnection() {
|
||||
return LazyDatabase(() async {
|
||||
final dbFolder = await getApplicationDocumentsDirectory();
|
||||
final file = File(join(dbFolder.path, 'massive.db'));
|
||||
final dbFolder = await getDatabasesPath();
|
||||
final file = File(join(dbFolder, 'massive.db'));
|
||||
print('file.path=${file.path}');
|
||||
return VmDatabase(file, logStatements: true);
|
||||
});
|
||||
}
|
||||
|
||||
+17
-17
@@ -10,7 +10,7 @@ part of 'database.dart';
|
||||
class Setting extends DataClass implements Insertable<Setting> {
|
||||
final bool alarm;
|
||||
final bool vibrate;
|
||||
final String sound;
|
||||
final String? sound;
|
||||
final bool notify;
|
||||
final bool images;
|
||||
final bool showUnit;
|
||||
@@ -26,7 +26,7 @@ class Setting extends DataClass implements Insertable<Setting> {
|
||||
Setting(
|
||||
{required this.alarm,
|
||||
required this.vibrate,
|
||||
required this.sound,
|
||||
this.sound,
|
||||
required this.notify,
|
||||
required this.images,
|
||||
required this.showUnit,
|
||||
@@ -48,7 +48,7 @@ class Setting extends DataClass implements Insertable<Setting> {
|
||||
vibrate: const BoolType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}vibrate'])!,
|
||||
sound: const StringType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}sound'])!,
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}sound']),
|
||||
notify: const BoolType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}notify'])!,
|
||||
images: const BoolType()
|
||||
@@ -80,7 +80,9 @@ class Setting extends DataClass implements Insertable<Setting> {
|
||||
final map = <String, Expression>{};
|
||||
map['alarm'] = Variable<bool>(alarm);
|
||||
map['vibrate'] = Variable<bool>(vibrate);
|
||||
map['sound'] = Variable<String>(sound);
|
||||
if (!nullToAbsent || sound != null) {
|
||||
map['sound'] = Variable<String?>(sound);
|
||||
}
|
||||
map['notify'] = Variable<bool>(notify);
|
||||
map['images'] = Variable<bool>(images);
|
||||
map['show_unit'] = Variable<bool>(showUnit);
|
||||
@@ -104,7 +106,8 @@ class Setting extends DataClass implements Insertable<Setting> {
|
||||
return SettingsCompanion(
|
||||
alarm: Value(alarm),
|
||||
vibrate: Value(vibrate),
|
||||
sound: Value(sound),
|
||||
sound:
|
||||
sound == null && nullToAbsent ? const Value.absent() : Value(sound),
|
||||
notify: Value(notify),
|
||||
images: Value(images),
|
||||
showUnit: Value(showUnit),
|
||||
@@ -130,7 +133,7 @@ class Setting extends DataClass implements Insertable<Setting> {
|
||||
return Setting(
|
||||
alarm: serializer.fromJson<bool>(json['alarm']),
|
||||
vibrate: serializer.fromJson<bool>(json['vibrate']),
|
||||
sound: serializer.fromJson<String>(json['sound']),
|
||||
sound: serializer.fromJson<String?>(json['sound']),
|
||||
notify: serializer.fromJson<bool>(json['notify']),
|
||||
images: serializer.fromJson<bool>(json['images']),
|
||||
showUnit: serializer.fromJson<bool>(json['showUnit']),
|
||||
@@ -151,7 +154,7 @@ class Setting extends DataClass implements Insertable<Setting> {
|
||||
return <String, dynamic>{
|
||||
'alarm': serializer.toJson<bool>(alarm),
|
||||
'vibrate': serializer.toJson<bool>(vibrate),
|
||||
'sound': serializer.toJson<String>(sound),
|
||||
'sound': serializer.toJson<String?>(sound),
|
||||
'notify': serializer.toJson<bool>(notify),
|
||||
'images': serializer.toJson<bool>(images),
|
||||
'showUnit': serializer.toJson<bool>(showUnit),
|
||||
@@ -263,7 +266,7 @@ class Setting extends DataClass implements Insertable<Setting> {
|
||||
class SettingsCompanion extends UpdateCompanion<Setting> {
|
||||
final Value<bool> alarm;
|
||||
final Value<bool> vibrate;
|
||||
final Value<String> sound;
|
||||
final Value<String?> sound;
|
||||
final Value<bool> notify;
|
||||
final Value<bool> images;
|
||||
final Value<bool> showUnit;
|
||||
@@ -296,7 +299,7 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
|
||||
SettingsCompanion.insert({
|
||||
required bool alarm,
|
||||
required bool vibrate,
|
||||
required String sound,
|
||||
this.sound = const Value.absent(),
|
||||
required bool notify,
|
||||
required bool images,
|
||||
required bool showUnit,
|
||||
@@ -311,7 +314,6 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
|
||||
required bool backup,
|
||||
}) : alarm = Value(alarm),
|
||||
vibrate = Value(vibrate),
|
||||
sound = Value(sound),
|
||||
notify = Value(notify),
|
||||
images = Value(images),
|
||||
showUnit = Value(showUnit),
|
||||
@@ -325,7 +327,7 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
|
||||
static Insertable<Setting> custom({
|
||||
Expression<bool>? alarm,
|
||||
Expression<bool>? vibrate,
|
||||
Expression<String>? sound,
|
||||
Expression<String?>? sound,
|
||||
Expression<bool>? notify,
|
||||
Expression<bool>? images,
|
||||
Expression<bool>? showUnit,
|
||||
@@ -361,7 +363,7 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
|
||||
SettingsCompanion copyWith(
|
||||
{Value<bool>? alarm,
|
||||
Value<bool>? vibrate,
|
||||
Value<String>? sound,
|
||||
Value<String?>? sound,
|
||||
Value<bool>? notify,
|
||||
Value<bool>? images,
|
||||
Value<bool>? showUnit,
|
||||
@@ -403,7 +405,7 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
|
||||
map['vibrate'] = Variable<bool>(vibrate.value);
|
||||
}
|
||||
if (sound.present) {
|
||||
map['sound'] = Variable<String>(sound.value);
|
||||
map['sound'] = Variable<String?>(sound.value);
|
||||
}
|
||||
if (notify.present) {
|
||||
map['notify'] = Variable<bool>(notify.value);
|
||||
@@ -489,8 +491,8 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> {
|
||||
final VerificationMeta _soundMeta = const VerificationMeta('sound');
|
||||
@override
|
||||
late final GeneratedColumn<String?> sound = GeneratedColumn<String?>(
|
||||
'sound', aliasedName, false,
|
||||
type: const StringType(), requiredDuringInsert: true);
|
||||
'sound', aliasedName, true,
|
||||
type: const StringType(), requiredDuringInsert: false);
|
||||
final VerificationMeta _notifyMeta = const VerificationMeta('notify');
|
||||
@override
|
||||
late final GeneratedColumn<bool?> notify = GeneratedColumn<bool?>(
|
||||
@@ -609,8 +611,6 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> {
|
||||
if (data.containsKey('sound')) {
|
||||
context.handle(
|
||||
_soundMeta, sound.isAcceptableOrUnknown(data['sound']!, _soundMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_soundMeta);
|
||||
}
|
||||
if (data.containsKey('notify')) {
|
||||
context.handle(_notifyMeta,
|
||||
|
||||
+5
-1
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/material.dart' as material;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:fmassive/database.dart';
|
||||
import 'package:fmassive/main.dart';
|
||||
import 'package:moor_flutter/moor_flutter.dart';
|
||||
@@ -112,8 +113,11 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
||||
onPressed: () async {
|
||||
if (gymSet.id.present)
|
||||
await db.update(db.gymSets).write(gymSet);
|
||||
else
|
||||
else {
|
||||
await db.into(db.gymSets).insert(gymSet);
|
||||
const platform = MethodChannel('com.massive/android');
|
||||
platform.invokeMethod('timer', [3000]);
|
||||
}
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context);
|
||||
},
|
||||
|
||||
@@ -33,6 +33,7 @@ class RootPage extends State<HomePage> {
|
||||
|
||||
void toggleSearch() {
|
||||
setState(() {
|
||||
if (showSearch) search = '';
|
||||
showSearch = !showSearch;
|
||||
});
|
||||
focusNode.requestFocus();
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ import 'package:moor/moor.dart';
|
||||
Setting defaultSettings = Setting(
|
||||
alarm: true,
|
||||
vibrate: true,
|
||||
sound: 'default.mp3',
|
||||
sound: null,
|
||||
notify: true,
|
||||
images: true,
|
||||
showUnit: true,
|
||||
@@ -22,7 +22,7 @@ Setting defaultSettings = Setting(
|
||||
class Settings extends Table {
|
||||
BoolColumn get alarm => boolean()();
|
||||
BoolColumn get vibrate => boolean()();
|
||||
TextColumn get sound => text()();
|
||||
TextColumn get sound => text().nullable()();
|
||||
BoolColumn get notify => boolean()();
|
||||
BoolColumn get images => boolean()();
|
||||
BoolColumn get showUnit => boolean()();
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/material.dart' as material;
|
||||
import 'package:fmassive/database.dart';
|
||||
import 'package:fmassive/main.dart';
|
||||
import 'package:fmassive/settings.dart';
|
||||
import 'package:moor/moor.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
@@ -30,15 +29,9 @@ class _SettingsPageState extends State<_SettingsPage> {
|
||||
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
|
||||
void reset() async {
|
||||
var data = await db.select(db.settings).get();
|
||||
if (data.isEmpty) await db.into(db.settings).insert(defaultSettings);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
reset();
|
||||
stream = db.select(db.settings).watchSingle();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user