diff --git a/lib/model/pb_setting.dart b/lib/model/pb_setting.dart index cf390da..fc1620c 100644 --- a/lib/model/pb_setting.dart +++ b/lib/model/pb_setting.dart @@ -1,11 +1,38 @@ -class PbSetting { - final String id; - final String type; - final String name; - final String config; - final String path; - final bool visible; +class PBSetting { + int _id; + String _type; + String _name; + String _config; + String _path; + bool _visible; - PbSetting(this.id, this.type, this.name, this.path, {this.config, this.visible}); + PBSetting(); -} \ No newline at end of file + int get id => _id; + String get type => _type; + String get name => _name; + String get config => _config; + String get path => _path; + bool get visible => _visible; + + PBSetting.fromMap(Map map) { + this._id = map['id']; + this._type = map['type']; + this._name = map['name']; + this._config = map['config']; + this._path = map['path']; + this._visible = map['visible'] == 1; + } + + Map toMap() { + var map = { + 'id': _id, + 'type': _type, + 'name': _name, + 'config': _config, + 'path': _path, + 'visible': _visible ? 1 : 0, + }; + return map; + } +} diff --git a/lib/utils/db_provider.dart b/lib/utils/db_provider.dart index 370610a..2676ef2 100644 --- a/lib/utils/db_provider.dart +++ b/lib/utils/db_provider.dart @@ -49,7 +49,7 @@ class DbProvider { path varchar(20) NOT NULL UNIQUE, name varchar(50) DEFAULT NULL, config varchar(255) DEFAULT NULL, - visible tinyint DEFAULT 1 + visible INTEGER DEFAULT 1 )'''); await db.execute(''' CREATE TABLE uploaded ( diff --git a/lib/utils/sql.dart b/lib/utils/sql.dart new file mode 100644 index 0000000..8bcfd4e --- /dev/null +++ b/lib/utils/sql.dart @@ -0,0 +1,29 @@ +import './db_provider.dart'; +import '../model/base.dart'; + +class Sql extends BaseModel { + + final String tableName; + + Sql.setTable(this.tableName) : super(DbProvider.db); + + // sdf + Future get() async { + return await this.query(tableName); + } + + String getTableName() { + return tableName; + } + + Future delete(String value, String key) async { + return await this + .db + .delete(tableName, where: '$key = ?', whereArgs: [value]); + } + + Future deleteAll() async { + return await this.db.delete(tableName); + } + +} diff --git a/lib/views/pb_setting_page/pb_setting_page.dart b/lib/views/pb_setting_page/pb_setting_page.dart index 6b96c82..a217d8b 100644 --- a/lib/views/pb_setting_page/pb_setting_page.dart +++ b/lib/views/pb_setting_page/pb_setting_page.dart @@ -1,9 +1,30 @@ import 'package:fluro/fluro.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_picgo/model/pb_setting.dart'; import 'package:flutter_picgo/routers/application.dart'; import 'package:flutter_picgo/routers/routers.dart'; +import 'package:flutter_picgo/views/pb_setting_page/pb_setting_presenter.dart'; -class PBSettingPage extends StatelessWidget { +class PBSettingPage extends StatefulWidget { + @override + _PBSettingPageState createState() => _PBSettingPageState(); +} + +class _PBSettingPageState extends State + implements PBSettingPageContract { + List _settings; + + PBSettingPagePresenter _presenter; + + _PBSettingPageState() { + _presenter = PBSettingPagePresenter(this); + } + + @override + void initState() { + super.initState(); + _presenter.doLoadPb(); + } @override Widget build(BuildContext context) { @@ -12,18 +33,32 @@ class PBSettingPage extends StatelessWidget { title: Text('图床设置'), centerTitle: true, ), - body: ListView( - children: [ - ListTile( - title: Text('Github图床'), - onTap: () { - Application.router.navigateTo(context, Routes.settingPbGithub, transition: TransitionType.cupertino); + body: this._settings == null + ? Center( + child: Text('暂无图床数据'), + ) + : ListView.builder( + itemCount: this._settings?.length ?? 0, + itemBuilder: (context, index) { + return ListTile( + title: Text(_settings[index].name), + onTap: () { + Application.router.navigateTo(context, _settings[index].path, transition: TransitionType.cupertino); + }, + trailing: Icon(Icons.arrow_right), + ); }, - trailing: Icon(Icons.arrow_right), ), - ], - ), ); } -} \ No newline at end of file + @override + void loadError(String errorMsg) {} + + @override + void loadPb(List settings) { + setState(() { + this._settings = settings; + }); + } +} diff --git a/lib/views/pb_setting_page/pb_setting_presenter.dart b/lib/views/pb_setting_page/pb_setting_presenter.dart new file mode 100644 index 0000000..7e8432f --- /dev/null +++ b/lib/views/pb_setting_page/pb_setting_presenter.dart @@ -0,0 +1,28 @@ +import 'package:flutter_picgo/model/pb_setting.dart'; +import 'package:flutter_picgo/utils/sql.dart'; + +abstract class PBSettingPageContract { + void loadPb(List settings); + + void loadError(String errorMsg); +} + +class PBSettingPagePresenter { + + PBSettingPageContract _view; + + PBSettingPagePresenter(this._view); + + doLoadPb() async { + try { + var sql = Sql.setTable('pb_setting'); + var list = await sql.get(); + var realList = list.map((map) { + return PBSetting.fromMap(map); + }).toList(); + _view.loadPb(realList); + } catch (e) { + _view.loadError(e); + } + } +} diff --git a/lib/views/setting_page/setting_page.dart b/lib/views/setting_page/setting_page.dart index cf1ead8..b1ffe85 100644 --- a/lib/views/setting_page/setting_page.dart +++ b/lib/views/setting_page/setting_page.dart @@ -47,7 +47,7 @@ class _SettingPageState extends State { height: 80, child: ClipOval( child: Image.asset( - 'images/logo.png', + 'assets/images/logo.png', fit: BoxFit.cover, width: 80, height: 80,