forked from lxm_tools/flutter-picgo
styles:完善页面中保存的提示
This commit is contained in:
21
lib/utils/db_provider.dart
Normal file
21
lib/utils/db_provider.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
class DbProvider {
|
||||
|
||||
static Database db;
|
||||
|
||||
// 获取数据库中所有的表
|
||||
Future<List> getTables() async {
|
||||
if (db == null) {
|
||||
return Future.value([]);
|
||||
}
|
||||
List tables = await db
|
||||
.rawQuery('SELECT name FROM sqlite_master WHERE type = "table"');
|
||||
List<String> targetList = [];
|
||||
tables.forEach((item) {
|
||||
targetList.add(item['name']);
|
||||
});
|
||||
return targetList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,14 +3,11 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_picgo/utils/shared_preferences.dart';
|
||||
|
||||
class PicGoSettingPage extends StatefulWidget {
|
||||
|
||||
@override
|
||||
_PicGoSettingPageState createState() => _PicGoSettingPageState();
|
||||
|
||||
}
|
||||
|
||||
class _PicGoSettingPageState extends State<PicGoSettingPage> {
|
||||
|
||||
bool isUploadedRename = false;
|
||||
bool isTimestampRename = false;
|
||||
bool isUploadedTip = false;
|
||||
@@ -20,9 +17,12 @@ class _PicGoSettingPageState extends State<PicGoSettingPage> {
|
||||
super.initState();
|
||||
SpUtil.getInstance().then((u) {
|
||||
setState(() {
|
||||
this.isUploadedRename = u?.getBool(SharedPreferencesKeys.settingIsUploadedRename) ?? false;
|
||||
this.isTimestampRename = u?.getBool(SharedPreferencesKeys.settingIsTimestampRename) ?? false;
|
||||
this.isUploadedTip = u?.getBool(SharedPreferencesKeys.settingIsUploadedTip) ?? false;
|
||||
this.isUploadedRename =
|
||||
u?.getBool(SharedPreferencesKeys.settingIsUploadedRename) ?? false;
|
||||
this.isTimestampRename =
|
||||
u?.getBool(SharedPreferencesKeys.settingIsTimestampRename) ?? false;
|
||||
this.isUploadedTip =
|
||||
u?.getBool(SharedPreferencesKeys.settingIsUploadedTip) ?? false;
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -34,64 +34,77 @@ class _PicGoSettingPageState extends State<PicGoSettingPage> {
|
||||
title: Text('PicGo设置'),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text('上传前重命名'),
|
||||
trailing: CupertinoSwitch(
|
||||
value: this.isUploadedRename,
|
||||
onChanged: (value) {
|
||||
this._save(SharedPreferencesKeys.settingIsUploadedRename, value);
|
||||
setState(() {
|
||||
this.isUploadedRename = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('时间戳重命名'),
|
||||
trailing: CupertinoSwitch(
|
||||
value: this.isTimestampRename,
|
||||
onChanged: (value) {
|
||||
this._save(SharedPreferencesKeys.settingIsTimestampRename, value);
|
||||
setState(() {
|
||||
this.isTimestampRename = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('开启上传提示'),
|
||||
trailing: CupertinoSwitch(
|
||||
value: this.isUploadedTip,
|
||||
onChanged: (value) {
|
||||
this._save(SharedPreferencesKeys.settingIsUploadedTip, value);
|
||||
setState(() {
|
||||
this.isUploadedTip = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('设置显示图床'),
|
||||
onTap: () {
|
||||
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text('检查更新'),
|
||||
onTap: () {
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
body: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return ListView(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text('上传前重命名'),
|
||||
trailing: CupertinoSwitch(
|
||||
value: this.isUploadedRename,
|
||||
onChanged: (value) {
|
||||
this._save(
|
||||
SharedPreferencesKeys.settingIsUploadedRename, value);
|
||||
setState(() {
|
||||
this.isUploadedRename = value;
|
||||
this._showTip(context);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('时间戳重命名'),
|
||||
trailing: CupertinoSwitch(
|
||||
value: this.isTimestampRename,
|
||||
onChanged: (value) {
|
||||
this._save(
|
||||
SharedPreferencesKeys.settingIsTimestampRename, value);
|
||||
this._showTip(context);
|
||||
setState(() {
|
||||
this.isTimestampRename = value;
|
||||
this._showTip(context);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('开启上传提示'),
|
||||
trailing: CupertinoSwitch(
|
||||
value: this.isUploadedTip,
|
||||
onChanged: (value) {
|
||||
this._save(
|
||||
SharedPreferencesKeys.settingIsUploadedTip, value);
|
||||
setState(() {
|
||||
this.isUploadedTip = value;
|
||||
this._showTip(context);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('设置显示图床'),
|
||||
onTap: () {},
|
||||
),
|
||||
ListTile(
|
||||
title: Text('检查更新'),
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showTip(BuildContext context) {
|
||||
final snackBar = SnackBar(
|
||||
content: Text('保存成功'),
|
||||
);
|
||||
Scaffold.of(context).showSnackBar(snackBar);
|
||||
}
|
||||
|
||||
void _save(String key, bool value) async {
|
||||
var instance = await SpUtil.getInstance();
|
||||
instance.putBool(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user