Add basic database import button

Still need to make sure we move across sets -> gym_sets
since moor won't let me use sets as a table name.

Moor doesnt like me having a class called sets with a property
called sets.
This commit is contained in:
Brandon Presley 2023-04-17 11:51:14 +12:00
parent 8bda4d593d
commit 0a7675797b
2 changed files with 30 additions and 1 deletions

View File

@ -23,7 +23,7 @@ class MyDatabase extends _$MyDatabase {
MigrationStrategy get migration => MigrationStrategy(
onCreate: (Migrator m) async {
await m.createAll();
var data = await;
var data = await (;
if (data.isEmpty) await db.into(db.settings).insert(defaultSettings);
onUpgrade: (Migrator m, int from, int to) async {

View File

@ -1,9 +1,14 @@
import 'dart:io';
import 'package:file_picker/file_picker.dart';
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/sound_picker.dart';
import 'package:moor/moor.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
class SettingsPage extends StatelessWidget {
const SettingsPage({super.key, required});
@ -57,6 +62,7 @@ class _SettingsPageState extends State<_SettingsPage> {
{'title': 'Show Unit', 'value': settings.showUnit},
{'title': 'Steps', 'value': settings.steps},
{'title': 'Sound', 'value': settings.sound},
{'title': 'Import', 'value': settings.sound},
.where((item) => (item['title'] as String)
@ -71,6 +77,29 @@ class _SettingsPageState extends State<_SettingsPage> {
itemBuilder: (context, index) {
final item = filteredItems[index];
if (item['title'] == 'Import')
return Center(
child: ElevatedButton(
onPressed: () async {
final result =
await FilePicker.platform.pickFiles(
type: FileType.any,
if (result == null) return;
final file = File(result.files.single.path!);
final path = await getDatabasesPath();
final to = join(path, 'massive.db');
await db.close();
await file.copy(to);
db = MyDatabase();
final migrator = db.createMigrator();
await migrator.createAll();
child: const Text("Import")));
if (item['title'] == 'Sound') {
return Center(
child: SoundPicker(