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:
parent
8bda4d593d
commit
0a7675797b
|
@ -23,7 +23,7 @@ class MyDatabase extends _$MyDatabase {
|
|||
MigrationStrategy get migration => MigrationStrategy(
|
||||
onCreate: (Migrator m) async {
|
||||
await m.createAll();
|
||||
var data = await db.select(db.settings).get();
|
||||
var data = await (db.select(db.settings)..limit(1)).get();
|
||||
if (data.isEmpty) await db.into(db.settings).insert(defaultSettings);
|
||||
},
|
||||
onUpgrade: (Migrator m, int from, int to) async {
|
||||
|
|
|
@ -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 this.search});
|
||||
|
@ -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)
|
||||
.toLowerCase()
|
||||
|
@ -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);
|
||||
print('Migrating...');
|
||||
db = MyDatabase();
|
||||
final migrator = db.createMigrator();
|
||||
await migrator.createAll();
|
||||
print('Migrated.');
|
||||
},
|
||||
child: const Text("Import")));
|
||||
|
||||
if (item['title'] == 'Sound') {
|
||||
return Center(
|
||||
child: SoundPicker(
|
||||
|
|
Loading…
Reference in New Issue
Block a user