BBreaking change
This commit is contained in:
18
lib/app.dart
18
lib/app.dart
@@ -1,4 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:toolbox/data/store/setting.dart';
|
||||||
|
import 'package:toolbox/locator.dart';
|
||||||
import 'package:toolbox/view/page/home.dart';
|
import 'package:toolbox/view/page/home.dart';
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@@ -7,13 +9,23 @@ class MyApp extends StatelessWidget {
|
|||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return ValueListenableBuilder<int>(
|
||||||
|
valueListenable: locator<SettingStore>().primaryColor.listenable(),
|
||||||
|
builder: (_, value, __) {
|
||||||
|
final primaryColor = Color(value);
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'ToolBox',
|
title: 'ToolBox',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
primaryColor: primaryColor,
|
||||||
|
appBarTheme: AppBarTheme(backgroundColor: primaryColor),
|
||||||
|
floatingActionButtonTheme:
|
||||||
|
FloatingActionButtonThemeData(backgroundColor: primaryColor),
|
||||||
|
iconTheme: IconThemeData(color: primaryColor),
|
||||||
|
primaryIconTheme: IconThemeData(color: primaryColor),
|
||||||
),
|
),
|
||||||
darkTheme: ThemeData.dark(),
|
darkTheme: ThemeData.dark().copyWith(primaryColor: primaryColor),
|
||||||
home: const MyHomePage(title: 'ToolBox'),
|
home: MyHomePage(primaryColor: primaryColor),
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
48
lib/data/model/private_key_info.dart
Normal file
48
lib/data/model/private_key_info.dart
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
|
||||||
|
///
|
||||||
|
class PrivateKeyInfo {
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"private_key": "",
|
||||||
|
"password": ""
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
late String id;
|
||||||
|
late String privateKey;
|
||||||
|
late String password;
|
||||||
|
|
||||||
|
PrivateKeyInfo(
|
||||||
|
this.id,
|
||||||
|
this.privateKey,
|
||||||
|
this.password,
|
||||||
|
);
|
||||||
|
PrivateKeyInfo.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json["id"].toString();
|
||||||
|
privateKey = json["private_key"].toString();
|
||||||
|
password = json["password"].toString();
|
||||||
|
}
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data["id"] = id;
|
||||||
|
data["private_key"] = privateKey;
|
||||||
|
data["password"] = password;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PrivateKeyInfo>? getPrivateKeyInfoList(dynamic data) {
|
||||||
|
List<PrivateKeyInfo> ss = [];
|
||||||
|
if (data is String) {
|
||||||
|
data = json.decode(data);
|
||||||
|
}
|
||||||
|
for (var t in data) {
|
||||||
|
ss.add(PrivateKeyInfo.fromJson(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
32
lib/data/provider/private_key.dart
Normal file
32
lib/data/provider/private_key.dart
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import 'package:toolbox/core/provider_base.dart';
|
||||||
|
import 'package:toolbox/data/model/private_key_info.dart';
|
||||||
|
import 'package:toolbox/data/store/private_key.dart';
|
||||||
|
import 'package:toolbox/locator.dart';
|
||||||
|
|
||||||
|
class PrivateKeyProvider extends BusyProvider {
|
||||||
|
List<PrivateKeyInfo> get infos => _infos;
|
||||||
|
late List<PrivateKeyInfo> _infos;
|
||||||
|
|
||||||
|
void loadData() {
|
||||||
|
_infos = locator<PrivateKeyStore>().fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addInfo(PrivateKeyInfo info) {
|
||||||
|
_infos.add(info);
|
||||||
|
locator<PrivateKeyStore>().put(info);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void delInfo(PrivateKeyInfo info) {
|
||||||
|
_infos.removeWhere((e) => e.id == info.id);
|
||||||
|
locator<PrivateKeyStore>().delete(info);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateInfo(PrivateKeyInfo old, PrivateKeyInfo newInfo) {
|
||||||
|
final idx = _infos.indexWhere((e) => e.id == old.id);
|
||||||
|
_infos[idx] = newInfo;
|
||||||
|
locator<PrivateKeyStore>().update(old, newInfo);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import 'package:toolbox/data/model/server_private_info.dart';
|
|||||||
import 'package:toolbox/data/model/server_status.dart';
|
import 'package:toolbox/data/model/server_status.dart';
|
||||||
import 'package:toolbox/data/model/tcp_status.dart';
|
import 'package:toolbox/data/model/tcp_status.dart';
|
||||||
import 'package:toolbox/data/store/server.dart';
|
import 'package:toolbox/data/store/server.dart';
|
||||||
|
import 'package:toolbox/data/store/setting.dart';
|
||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
|
|
||||||
class ServerProvider extends BusyProvider {
|
class ServerProvider extends BusyProvider {
|
||||||
@@ -55,8 +56,13 @@ class ServerProvider extends BusyProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refreshData() async {
|
Future<void> refreshData() async {
|
||||||
final _serversStatus = await Future.wait(
|
List<ServerStatus> _serversStatus = [];
|
||||||
|
try {
|
||||||
|
_serversStatus = await Future.wait(
|
||||||
_servers.map((s) => _getData(s.info, _servers.indexOf(s))));
|
_servers.map((s) => _getData(s.info, _servers.indexOf(s))));
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (var item in _serversStatus) {
|
for (var item in _serversStatus) {
|
||||||
_servers[idx].status = item;
|
_servers[idx].status = item;
|
||||||
@@ -64,9 +70,14 @@ class ServerProvider extends BusyProvider {
|
|||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> startAutoRefresh() async {
|
Future<void> startAutoRefresh() async {
|
||||||
Timer.periodic(const Duration(seconds: 3), (_) async {
|
Timer.periodic(
|
||||||
|
Duration(
|
||||||
|
seconds: locator<SettingStore>()
|
||||||
|
.serverStatusUpdateInterval
|
||||||
|
.fetch()!), (_) async {
|
||||||
await refreshData();
|
await refreshData();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
class BuildData {
|
class BuildData {
|
||||||
static const String name = "ToolBox";
|
static const String name = "ToolBox";
|
||||||
static const int build = 18;
|
static const int build = 20;
|
||||||
static const String engine =
|
static const String engine =
|
||||||
"Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (10 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
|
"Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (10 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
|
||||||
static const String buildAt = "2021-10-25 16:56:13.551427";
|
static const String buildAt = "2021-10-26 00:28:50.061797";
|
||||||
static const int modifications = 0;
|
static const int modifications = 21;
|
||||||
}
|
}
|
||||||
|
|||||||
33
lib/data/store/private_key.dart
Normal file
33
lib/data/store/private_key.dart
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:toolbox/core/persistant_store.dart';
|
||||||
|
import 'package:toolbox/data/model/private_key_info.dart';
|
||||||
|
|
||||||
|
class PrivateKeyStore extends PersistentStore {
|
||||||
|
void put(PrivateKeyInfo info) {
|
||||||
|
final ss = fetch();
|
||||||
|
if (!have(info)) ss.add(info);
|
||||||
|
box.put('key', json.encode(ss));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PrivateKeyInfo> fetch() {
|
||||||
|
return getPrivateKeyInfoList(
|
||||||
|
json.decode(box.get('key', defaultValue: '[]')!))!;
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete(PrivateKeyInfo s) {
|
||||||
|
final ss = fetch();
|
||||||
|
ss.removeAt(index(s));
|
||||||
|
box.put('key', json.encode(ss));
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(PrivateKeyInfo old, PrivateKeyInfo newInfo) {
|
||||||
|
final ss = fetch();
|
||||||
|
ss[index(old)] = newInfo;
|
||||||
|
box.put('key', json.encode(ss));
|
||||||
|
}
|
||||||
|
|
||||||
|
int index(PrivateKeyInfo s) => fetch().indexWhere((e) => e.id == s.id);
|
||||||
|
|
||||||
|
bool have(PrivateKeyInfo s) => index(s) != -1;
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:toolbox/core/persistant_store.dart';
|
import 'package:toolbox/core/persistant_store.dart';
|
||||||
|
|
||||||
class SettingStore extends PersistentStore {
|
class SettingStore extends PersistentStore {
|
||||||
StoreProperty<bool> get receiveNotification =>
|
StoreProperty<int> get primaryColor =>
|
||||||
property('notify', defaultValue: true);
|
property('primaryColor', defaultValue: Colors.deepPurpleAccent.value);
|
||||||
|
StoreProperty<int> get serverStatusUpdateInterval =>
|
||||||
|
property('serverStatusUpdateInterval', defaultValue: 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
import 'package:toolbox/data/provider/app.dart';
|
import 'package:toolbox/data/provider/app.dart';
|
||||||
import 'package:toolbox/data/provider/debug.dart';
|
import 'package:toolbox/data/provider/debug.dart';
|
||||||
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
import 'package:toolbox/data/service/app.dart';
|
import 'package:toolbox/data/service/app.dart';
|
||||||
|
import 'package:toolbox/data/store/private_key.dart';
|
||||||
import 'package:toolbox/data/store/server.dart';
|
import 'package:toolbox/data/store/server.dart';
|
||||||
import 'package:toolbox/data/store/setting.dart';
|
import 'package:toolbox/data/store/setting.dart';
|
||||||
|
|
||||||
@@ -16,6 +18,7 @@ void setupLocatorForProviders() {
|
|||||||
locator.registerSingleton(AppProvider());
|
locator.registerSingleton(AppProvider());
|
||||||
locator.registerSingleton(DebugProvider());
|
locator.registerSingleton(DebugProvider());
|
||||||
locator.registerSingleton(ServerProvider());
|
locator.registerSingleton(ServerProvider());
|
||||||
|
locator.registerSingleton(PrivateKeyProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setupLocatorForStores() async {
|
Future<void> setupLocatorForStores() async {
|
||||||
@@ -26,6 +29,10 @@ Future<void> setupLocatorForStores() async {
|
|||||||
final server = ServerStore();
|
final server = ServerStore();
|
||||||
await server.init(boxName: 'server');
|
await server.init(boxName: 'server');
|
||||||
locator.registerSingleton(server);
|
locator.registerSingleton(server);
|
||||||
|
|
||||||
|
final key = PrivateKeyStore();
|
||||||
|
await key.init(boxName: 'key');
|
||||||
|
locator.registerSingleton(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setupLocator() async {
|
Future<void> setupLocator() async {
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ import 'package:toolbox/app.dart';
|
|||||||
import 'package:toolbox/core/analysis.dart';
|
import 'package:toolbox/core/analysis.dart';
|
||||||
import 'package:toolbox/data/provider/app.dart';
|
import 'package:toolbox/data/provider/app.dart';
|
||||||
import 'package:toolbox/data/provider/debug.dart';
|
import 'package:toolbox/data/provider/debug.dart';
|
||||||
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
|
|
||||||
Future<void> initApp() async {
|
Future<void> initApp() async {
|
||||||
await Hive.initFlutter();
|
await Hive.initFlutter();
|
||||||
await setupLocator();
|
await setupLocator();
|
||||||
|
locator<PrivateKeyProvider>().loadData();
|
||||||
|
|
||||||
///设置Logger
|
///设置Logger
|
||||||
Logger.root.level = Level.ALL; // defaults to Level.INFO
|
Logger.root.level = Level.ALL; // defaults to Level.INFO
|
||||||
@@ -60,6 +62,7 @@ Future<void> main() async {
|
|||||||
ChangeNotifierProvider(create: (_) => locator<AppProvider>()),
|
ChangeNotifierProvider(create: (_) => locator<AppProvider>()),
|
||||||
ChangeNotifierProvider(create: (_) => locator<DebugProvider>()),
|
ChangeNotifierProvider(create: (_) => locator<DebugProvider>()),
|
||||||
ChangeNotifierProvider(create: (_) => locator<ServerProvider>()),
|
ChangeNotifierProvider(create: (_) => locator<ServerProvider>()),
|
||||||
|
ChangeNotifierProvider(create: (_) => locator<PrivateKeyProvider>()),
|
||||||
],
|
],
|
||||||
child: const MyApp(),
|
child: const MyApp(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -9,11 +9,14 @@ import 'package:toolbox/data/res/build_data.dart';
|
|||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
import 'package:toolbox/view/page/convert.dart';
|
import 'package:toolbox/view/page/convert.dart';
|
||||||
import 'package:toolbox/view/page/debug.dart';
|
import 'package:toolbox/view/page/debug.dart';
|
||||||
import 'package:toolbox/view/page/server/server_tab.dart';
|
import 'package:toolbox/view/page/private_key/stored.dart';
|
||||||
|
import 'package:toolbox/view/page/server/tab.dart';
|
||||||
|
import 'package:toolbox/view/page/setting.dart';
|
||||||
|
import 'package:toolbox/view/widget/url_text.dart';
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
class MyHomePage extends StatefulWidget {
|
||||||
const MyHomePage({Key? key, required this.title}) : super(key: key);
|
const MyHomePage({Key? key, required this.primaryColor}) : super(key: key);
|
||||||
final String title;
|
final Color primaryColor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
State<MyHomePage> createState() => _MyHomePageState();
|
||||||
@@ -42,9 +45,10 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
title: GestureDetector(
|
title: GestureDetector(
|
||||||
onLongPress: () =>
|
onLongPress: () =>
|
||||||
AppRoute(const DebugPage(), 'Debug Page').go(context),
|
AppRoute(const DebugPage(), 'Debug Page').go(context),
|
||||||
child: Text(widget.title),
|
child: const Text('ToolBox'),
|
||||||
),
|
),
|
||||||
bottom: TabBar(
|
bottom: TabBar(
|
||||||
|
indicatorColor: widget.primaryColor,
|
||||||
tabs: _tabs.map((e) => Tab(text: e)).toList(),
|
tabs: _tabs.map((e) => Tab(text: e)).toList(),
|
||||||
controller: _tabController,
|
controller: _tabController,
|
||||||
),
|
),
|
||||||
@@ -67,19 +71,27 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
accountEmail: Text(_buildVersionStr()),
|
accountEmail: Text(_buildVersionStr()),
|
||||||
currentAccountPicture: _buildIcon(),
|
currentAccountPicture: _buildIcon(),
|
||||||
),
|
),
|
||||||
// const ListTile(
|
ListTile(
|
||||||
// leading: Icon(Icons.settings),
|
leading: const Icon(Icons.settings),
|
||||||
// title: Text('设置'),
|
title: const Text('Setting'),
|
||||||
// ),
|
onTap: () => AppRoute(const SettingPage(), 'Setting').go(context),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.vpn_key),
|
||||||
|
title: const Text('Private Key'),
|
||||||
|
onTap: () =>
|
||||||
|
AppRoute(const StoredPrivateKeysPage(), 'Setting').go(context),
|
||||||
|
),
|
||||||
AboutListTile(
|
AboutListTile(
|
||||||
icon: const Icon(Icons.text_snippet),
|
icon: const Icon(Icons.text_snippet),
|
||||||
child: const Text('Open source licenses'),
|
child: const Text('Licences'),
|
||||||
applicationName: BuildData.name,
|
applicationName: BuildData.name,
|
||||||
applicationVersion: _buildVersionStr(),
|
applicationVersion: _buildVersionStr(),
|
||||||
applicationIcon: _buildIcon(),
|
applicationIcon: _buildIcon(),
|
||||||
aboutBoxChildren: const [
|
aboutBoxChildren: const [
|
||||||
Text('''\nMade with Love.
|
UrlText(
|
||||||
\nAll rights reserved.'''),
|
text: '''\nMade with ❤️ by https://github.com/LollipopKit .
|
||||||
|
\nAll rights reserved.''', replace: 'LollipopKit'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
98
lib/view/page/private_key/edit.dart
Normal file
98
lib/view/page/private_key/edit.dart
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import 'package:after_layout/after_layout.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:toolbox/data/model/private_key_info.dart';
|
||||||
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
|
import 'package:toolbox/locator.dart';
|
||||||
|
|
||||||
|
class PrivateKeyEditPage extends StatefulWidget {
|
||||||
|
const PrivateKeyEditPage({Key? key, this.info}) : super(key: key);
|
||||||
|
|
||||||
|
final PrivateKeyInfo? info;
|
||||||
|
|
||||||
|
@override
|
||||||
|
_PrivateKeyEditPageState createState() => _PrivateKeyEditPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||||
|
with AfterLayoutMixin {
|
||||||
|
final nameController = TextEditingController();
|
||||||
|
final keyController = TextEditingController();
|
||||||
|
final pwdController = TextEditingController();
|
||||||
|
|
||||||
|
late PrivateKeyProvider _provider;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_provider = locator<PrivateKeyProvider>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Edit'), actions: [
|
||||||
|
widget.info != null
|
||||||
|
? IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
_provider.delInfo(widget.info!);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.delete))
|
||||||
|
: const SizedBox()
|
||||||
|
]),
|
||||||
|
body: ListView(
|
||||||
|
padding: const EdgeInsets.all(13),
|
||||||
|
children: [
|
||||||
|
TextField(
|
||||||
|
controller: nameController,
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
decoration: _buildDecoration('Name', icon: Icons.info),
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
controller: keyController,
|
||||||
|
autocorrect: false,
|
||||||
|
minLines: 3,
|
||||||
|
maxLines: 10,
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
decoration: _buildDecoration('Private Key', icon: Icons.vpn_key),
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
controller: pwdController,
|
||||||
|
autocorrect: false,
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
obscureText: true,
|
||||||
|
decoration: _buildDecoration('Password', icon: Icons.password),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
child: const Icon(Icons.send),
|
||||||
|
onPressed: () {
|
||||||
|
final info = PrivateKeyInfo(
|
||||||
|
nameController.text, keyController.text, pwdController.text);
|
||||||
|
if (widget.info != null) {
|
||||||
|
_provider.updateInfo(widget.info!, info);
|
||||||
|
} else {
|
||||||
|
_provider.addInfo(info);
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
InputDecoration _buildDecoration(String label,
|
||||||
|
{TextStyle? textStyle, IconData? icon}) {
|
||||||
|
return InputDecoration(
|
||||||
|
labelText: label, labelStyle: textStyle, icon: Icon(icon));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void afterFirstLayout(BuildContext context) {
|
||||||
|
if (widget.info != null) {
|
||||||
|
nameController.text = widget.info!.id;
|
||||||
|
keyController.text = widget.info!.privateKey;
|
||||||
|
pwdController.text = widget.info!.password;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
58
lib/view/page/private_key/stored.dart
Normal file
58
lib/view/page/private_key/stored.dart
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:toolbox/core/route.dart';
|
||||||
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
|
import 'package:toolbox/view/page/private_key/edit.dart';
|
||||||
|
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||||
|
|
||||||
|
class StoredPrivateKeysPage extends StatefulWidget {
|
||||||
|
const StoredPrivateKeysPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_PrivateKeyListState createState() => _PrivateKeyListState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Private Keys'),
|
||||||
|
),
|
||||||
|
body: Consumer<PrivateKeyProvider>(
|
||||||
|
builder: (_, key, __) {
|
||||||
|
return key.infos.isNotEmpty
|
||||||
|
? ListView.builder(
|
||||||
|
padding: const EdgeInsets.all(13),
|
||||||
|
itemCount: key.infos.length,
|
||||||
|
itemExtent: 57,
|
||||||
|
itemBuilder: (context, idx) {
|
||||||
|
return RoundRectCard(Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
key.infos[idx].id,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => AppRoute(
|
||||||
|
PrivateKeyEditPage(info: key.infos[idx]),
|
||||||
|
'private key edit page')
|
||||||
|
.go(context),
|
||||||
|
child: const Text('Edit'))
|
||||||
|
],
|
||||||
|
));
|
||||||
|
})
|
||||||
|
: const Center(child: Text('No saved private keys.'));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
child: const Icon(Icons.add),
|
||||||
|
onPressed: () =>
|
||||||
|
AppRoute(const PrivateKeyEditPage(), 'private key edit page')
|
||||||
|
.go(context),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
import 'package:after_layout/after_layout.dart';
|
import 'package:after_layout/after_layout.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:toolbox/core/route.dart';
|
||||||
|
import 'package:toolbox/core/utils.dart';
|
||||||
import 'package:toolbox/data/model/server_private_info.dart';
|
import 'package:toolbox/data/model/server_private_info.dart';
|
||||||
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
|
import 'package:toolbox/view/page/private_key/edit.dart';
|
||||||
|
|
||||||
class ServerEditPage extends StatefulWidget {
|
class ServerEditPage extends StatefulWidget {
|
||||||
const ServerEditPage({Key? key, this.spi}) : super(key: key);
|
const ServerEditPage({Key? key, this.spi}) : super(key: key);
|
||||||
@@ -25,6 +30,9 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
|
|
||||||
bool usePublicKey = false;
|
bool usePublicKey = false;
|
||||||
|
|
||||||
|
int _typeOptionIndex = -1;
|
||||||
|
final List<String> _keyInfo = ['', ''];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -34,7 +42,16 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: const Text('Edit')),
|
appBar: AppBar(title: const Text('Edit'), actions: [
|
||||||
|
widget.spi != null
|
||||||
|
? IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
_serverProvider.delServer(widget.spi!);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.delete))
|
||||||
|
: const SizedBox()
|
||||||
|
]),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.all(17),
|
padding: const EdgeInsets.all(17),
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -49,6 +66,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
TextField(
|
TextField(
|
||||||
controller: ipController,
|
controller: ipController,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
autocorrect: false,
|
||||||
decoration: _buildDecoration('Host', icon: Icons.storage),
|
decoration: _buildDecoration('Host', icon: Icons.storage),
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
@@ -60,6 +78,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
TextField(
|
TextField(
|
||||||
controller: usernameController,
|
controller: usernameController,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
autocorrect: false,
|
||||||
decoration: _buildDecoration('User', icon: Icons.account_box),
|
decoration: _buildDecoration('User', icon: Icons.account_box),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 7),
|
const SizedBox(height: 7),
|
||||||
@@ -71,37 +90,59 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
onChanged: (val) => setState(() => usePublicKey = val)),
|
onChanged: (val) => setState(() => usePublicKey = val)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
usePublicKey
|
!usePublicKey
|
||||||
? TextField(
|
? TextField(
|
||||||
controller: keyController,
|
|
||||||
keyboardType: TextInputType.text,
|
|
||||||
autocorrect: false,
|
|
||||||
maxLines: 10,
|
|
||||||
minLines: 5,
|
|
||||||
decoration:
|
|
||||||
_buildDecoration('Private Key', icon: Icons.vpn_key),
|
|
||||||
onSubmitted: (_) => {},
|
|
||||||
)
|
|
||||||
: const SizedBox(),
|
|
||||||
TextField(
|
|
||||||
controller: passwordController,
|
controller: passwordController,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
decoration: _buildDecoration('Pwd', icon: Icons.password),
|
decoration: _buildDecoration('Pwd', icon: Icons.password),
|
||||||
onSubmitted: (_) => {},
|
onSubmitted: (_) => {},
|
||||||
|
)
|
||||||
|
: const SizedBox(),
|
||||||
|
usePublicKey
|
||||||
|
? Consumer<PrivateKeyProvider>(builder: (_, key, __) {
|
||||||
|
final tiles = key.infos
|
||||||
|
.map(
|
||||||
|
(e) => ListTile(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
title: Text(e.id, textAlign: TextAlign.start),
|
||||||
|
trailing: _buildRadio(key.infos.indexOf(e),
|
||||||
|
e.privateKey, e.password)),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
tiles.add(ListTile(
|
||||||
|
title: const Text('Add a Private Key'),
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
onPressed: () => AppRoute(const PrivateKeyEditPage(),
|
||||||
|
'private key edit page')
|
||||||
|
.go(context),
|
||||||
),
|
),
|
||||||
|
));
|
||||||
|
return ExpansionTile(
|
||||||
|
tilePadding: EdgeInsets.zero,
|
||||||
|
childrenPadding: EdgeInsets.zero,
|
||||||
|
title: const Text(
|
||||||
|
'Choose Key',
|
||||||
|
style: TextStyle(fontSize: 14),
|
||||||
|
),
|
||||||
|
children: tiles,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
: const SizedBox()
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: const Icon(Icons.send),
|
child: const Icon(Icons.send),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final authorization = keyController.text.isEmpty
|
if (usePublicKey && _typeOptionIndex == -1) {
|
||||||
? passwordController.text
|
showSnackBar(context, const Text('Please select a private key.'));
|
||||||
: {
|
}
|
||||||
"privateKey": keyController.text,
|
final authorization = usePublicKey
|
||||||
"passphrase": passwordController.text
|
? {"privateKey": _keyInfo[0], "passphrase": _keyInfo[1]}
|
||||||
};
|
: passwordController.text;
|
||||||
final spi = ServerPrivateInfo(
|
final spi = ServerPrivateInfo(
|
||||||
name: nameController.text,
|
name: nameController.text,
|
||||||
ip: ipController.text,
|
ip: ipController.text,
|
||||||
@@ -121,6 +162,20 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Radio _buildRadio(int index, String key, String pwd) {
|
||||||
|
return Radio<int>(
|
||||||
|
value: index,
|
||||||
|
groupValue: _typeOptionIndex,
|
||||||
|
onChanged: (int? value) {
|
||||||
|
setState(() {
|
||||||
|
_typeOptionIndex = value!;
|
||||||
|
_keyInfo[0] = key;
|
||||||
|
_keyInfo[1] = pwd;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
InputDecoration _buildDecoration(String label,
|
InputDecoration _buildDecoration(String label,
|
||||||
{TextStyle? textStyle, IconData? icon}) {
|
{TextStyle? textStyle, IconData? icon}) {
|
||||||
return InputDecoration(
|
return InputDecoration(
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:after_layout/after_layout.dart';
|
import 'package:after_layout/after_layout.dart';
|
||||||
import 'package:charts_flutter/flutter.dart' as chart;
|
import 'package:circle_chart/circle_chart.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||||
@@ -9,9 +9,9 @@ import 'package:toolbox/core/route.dart';
|
|||||||
import 'package:toolbox/data/model/server_private_info.dart';
|
import 'package:toolbox/data/model/server_private_info.dart';
|
||||||
import 'package:toolbox/data/model/server_status.dart';
|
import 'package:toolbox/data/model/server_status.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
|
import 'package:toolbox/data/store/setting.dart';
|
||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
import 'package:toolbox/view/page/server/server_edit.dart';
|
import 'package:toolbox/view/page/server/edit.dart';
|
||||||
import 'package:toolbox/view/widget/circle_pie.dart';
|
|
||||||
|
|
||||||
class ServerPage extends StatefulWidget {
|
class ServerPage extends StatefulWidget {
|
||||||
const ServerPage({Key? key}) : super(key: key);
|
const ServerPage({Key? key}) : super(key: key);
|
||||||
@@ -24,6 +24,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
with AutomaticKeepAliveClientMixin, AfterLayoutMixin {
|
with AutomaticKeepAliveClientMixin, AfterLayoutMixin {
|
||||||
late MediaQueryData _media;
|
late MediaQueryData _media;
|
||||||
late ThemeData _theme;
|
late ThemeData _theme;
|
||||||
|
late Color _primaryColor;
|
||||||
|
|
||||||
late ServerProvider _serverProvider;
|
late ServerProvider _serverProvider;
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
_media = MediaQuery.of(context);
|
_media = MediaQuery.of(context);
|
||||||
_theme = Theme.of(context);
|
_theme = Theme.of(context);
|
||||||
|
_primaryColor = Color(locator<SettingStore>().primaryColor.fetch()!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -102,19 +104,6 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildRealServerCard(ServerStatus ss, String serverName) {
|
Widget _buildRealServerCard(ServerStatus ss, String serverName) {
|
||||||
final cpuData = [
|
|
||||||
IndexPercent(0, ss.cpuPercent!.toInt()),
|
|
||||||
IndexPercent(1, 100 - ss.cpuPercent!.toInt()),
|
|
||||||
];
|
|
||||||
final memData = <IndexPercent>[];
|
|
||||||
for (var e in ss.memList!) {
|
|
||||||
memData.add(IndexPercent(ss.memList!.indexOf(e), e!.toInt()));
|
|
||||||
}
|
|
||||||
|
|
||||||
final mem1 = memData[1];
|
|
||||||
memData[1] = memData.last;
|
|
||||||
memData.last = mem1;
|
|
||||||
|
|
||||||
final rootDisk =
|
final rootDisk =
|
||||||
ss.disk!.firstWhere((element) => element!.mountLocation == '/');
|
ss.disk!.firstWhere((element) => element!.mountLocation == '/');
|
||||||
|
|
||||||
@@ -139,23 +128,9 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
_buildPercentCircle(ss.cpuPercent!, 'CPU', [
|
_buildPercentCircle(ss.cpuPercent! + 0.01, 'CPU'),
|
||||||
chart.Series<IndexPercent, int>(
|
|
||||||
id: 'CPU',
|
|
||||||
domainFn: (IndexPercent cpu, _) => cpu.id,
|
|
||||||
measureFn: (IndexPercent cpu, _) => cpu.percent,
|
|
||||||
data: cpuData,
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
_buildPercentCircle(
|
_buildPercentCircle(
|
||||||
ss.memList![1]! / ss.memList![0]! * 100, 'Mem', [
|
ss.memList![1]! / ss.memList![0]! * 100 + 0.01, 'Mem'),
|
||||||
chart.Series<IndexPercent, int>(
|
|
||||||
id: 'Mem',
|
|
||||||
domainFn: (IndexPercent mem, _) => mem.id,
|
|
||||||
measureFn: (IndexPercent mem, _) => mem.percent,
|
|
||||||
data: memData,
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
_buildIOData('Net', 'Conn:\n' + ss.tcp!.maxConn!.toString(),
|
_buildIOData('Net', 'Conn:\n' + ss.tcp!.maxConn!.toString(),
|
||||||
'Fail:\n' + ss.tcp!.fail.toString()),
|
'Fail:\n' + ss.tcp!.fail.toString()),
|
||||||
_buildIOData('Disk', 'Total:\n' + rootDisk!.size!,
|
_buildIOData('Disk', 'Total:\n' + rootDisk!.size!,
|
||||||
@@ -172,10 +147,6 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: _media.size.width * 0.2,
|
width: _media.size.width * 0.2,
|
||||||
height: _media.size.height * 0.1,
|
height: _media.size.height * 0.1,
|
||||||
child: Stack(
|
|
||||||
children: [
|
|
||||||
Positioned.fill(
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
@@ -189,42 +160,40 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
down + '\n',
|
down + '\n',
|
||||||
style: statusTextStyle,
|
style: statusTextStyle,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
Text(title, textAlign: TextAlign.center)
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
child: Text(title, textAlign: TextAlign.center),
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPercentCircle(double percent, String title,
|
Widget _buildPercentCircle(double percent, String title) {
|
||||||
List<chart.Series<IndexPercent, int>> series) {
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: _media.size.width * 0.2,
|
width: _media.size.width * 0.2,
|
||||||
height: _media.size.height * 0.1,
|
height: _media.size.height * 0.1,
|
||||||
child: Stack(
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
DonutPieChart(series),
|
Stack(
|
||||||
|
children: [
|
||||||
|
CircleChart(
|
||||||
|
progressColor: _primaryColor,
|
||||||
|
progressNumber: percent,
|
||||||
|
maxNumber: 100,
|
||||||
|
width: _media.size.width * 0.37,
|
||||||
|
height: _media.size.height * 0.09,
|
||||||
|
),
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'${percent.toStringAsFixed(1)}%\n',
|
'${percent.toStringAsFixed(1)}%',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Positioned(
|
],
|
||||||
child: Text(title, textAlign: TextAlign.center),
|
),
|
||||||
bottom: 0,
|
Text(title, textAlign: TextAlign.center),
|
||||||
left: 0,
|
|
||||||
right: 0)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
108
lib/view/page/setting.dart
Normal file
108
lib/view/page/setting.dart
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
|
||||||
|
import 'package:toolbox/core/utils.dart';
|
||||||
|
import 'package:toolbox/data/store/setting.dart';
|
||||||
|
import 'package:toolbox/locator.dart';
|
||||||
|
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||||
|
|
||||||
|
class SettingPage extends StatefulWidget {
|
||||||
|
const SettingPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SettingPageState createState() => _SettingPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SettingPageState extends State<SettingPage> {
|
||||||
|
late SettingStore _store;
|
||||||
|
late int _selectedColorValue;
|
||||||
|
final TextEditingController _intervalController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_store = locator<SettingStore>();
|
||||||
|
_intervalController.text =
|
||||||
|
_store.serverStatusUpdateInterval.fetch()!.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Setting'),
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
padding: const EdgeInsets.all(17),
|
||||||
|
children: [
|
||||||
|
RoundRectCard(_buildAppColorPreview()),
|
||||||
|
RoundRectCard(
|
||||||
|
ListTile(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
title: const Text(
|
||||||
|
'Server status update interval (seconds)',
|
||||||
|
style: TextStyle(fontSize: 14),
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
),
|
||||||
|
trailing: SizedBox(
|
||||||
|
width: MediaQuery.of(context).size.width * 0.1,
|
||||||
|
child: TextField(
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
controller: _intervalController,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
onSubmitted: (val) {
|
||||||
|
_store.serverStatusUpdateInterval.put(int.parse(val));
|
||||||
|
showSnackBar(
|
||||||
|
context,
|
||||||
|
const Text(
|
||||||
|
'This setting will take effect \nthe next time app launch'));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildAppColorPreview() {
|
||||||
|
final nowAppColor = _store.primaryColor.fetch()!;
|
||||||
|
return ExpansionTile(
|
||||||
|
tilePadding: EdgeInsets.zero,
|
||||||
|
childrenPadding: EdgeInsets.zero,
|
||||||
|
children: [
|
||||||
|
_buildAppColorPicker(Color(nowAppColor)),
|
||||||
|
_buildColorPickerConfirmBtn()
|
||||||
|
],
|
||||||
|
trailing: ClipOval(
|
||||||
|
child: Container(
|
||||||
|
color: Color(nowAppColor),
|
||||||
|
height: 27,
|
||||||
|
width: 27,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
'App primary color',
|
||||||
|
style: TextStyle(fontSize: 14),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildAppColorPicker(Color selected) {
|
||||||
|
return MaterialColorPicker(
|
||||||
|
shrinkWrap: true,
|
||||||
|
onColorChange: (Color color) {
|
||||||
|
_selectedColorValue = color.value;
|
||||||
|
},
|
||||||
|
selectedColor: selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildColorPickerConfirmBtn() {
|
||||||
|
return IconButton(
|
||||||
|
icon: const Icon(Icons.save),
|
||||||
|
onPressed: (() {
|
||||||
|
_store.primaryColor.put(_selectedColorValue);
|
||||||
|
setState(() {});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import 'package:charts_flutter/flutter.dart' as charts;
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class DonutPieChart extends StatelessWidget {
|
|
||||||
final List<charts.Series<dynamic, num>> seriesList;
|
|
||||||
final bool animate;
|
|
||||||
|
|
||||||
const DonutPieChart(this.seriesList, {Key? key, this.animate = false})
|
|
||||||
: super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return charts.PieChart(seriesList,
|
|
||||||
animate: animate,
|
|
||||||
layoutConfig: charts.LayoutConfig(
|
|
||||||
leftMarginSpec: charts.MarginSpec.fixedPixel(1),
|
|
||||||
topMarginSpec: charts.MarginSpec.fixedPixel(1),
|
|
||||||
rightMarginSpec: charts.MarginSpec.fixedPixel(1),
|
|
||||||
bottomMarginSpec: charts.MarginSpec.fixedPixel(17)),
|
|
||||||
defaultRenderer: charts.ArcRendererConfig<num>(
|
|
||||||
arcWidth: 6,
|
|
||||||
arcRatio: 0.2,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class IndexPercent {
|
|
||||||
final int id;
|
|
||||||
final int percent;
|
|
||||||
|
|
||||||
IndexPercent(this.id, this.percent);
|
|
||||||
}
|
|
||||||
20
lib/view/widget/round_rect_card.dart
Normal file
20
lib/view/widget/round_rect_card.dart
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class RoundRectCard extends StatelessWidget {
|
||||||
|
const RoundRectCard(this.child, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Card(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 17),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 7),
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(17))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
91
lib/view/widget/url_text.dart
Normal file
91
lib/view/widget/url_text.dart
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import 'package:flutter/gestures.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:toolbox/core/utils.dart';
|
||||||
|
|
||||||
|
const regUrl =
|
||||||
|
r"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]*";
|
||||||
|
|
||||||
|
class UrlText extends StatelessWidget {
|
||||||
|
final String text;
|
||||||
|
final String? replace;
|
||||||
|
final TextStyle style;
|
||||||
|
|
||||||
|
const UrlText(
|
||||||
|
{Key? key,
|
||||||
|
required this.text,
|
||||||
|
this.replace,
|
||||||
|
this.style = const TextStyle()})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
List<InlineSpan> _getTextSpans(bool isDarkMode) {
|
||||||
|
List<InlineSpan> widgets = <InlineSpan>[];
|
||||||
|
final reg = RegExp(regUrl);
|
||||||
|
Iterable<Match> _matches = reg.allMatches(text);
|
||||||
|
List<_ResultMatch> resultMatches = <_ResultMatch>[];
|
||||||
|
int start = 0;
|
||||||
|
|
||||||
|
for (Match match in _matches) {
|
||||||
|
final group0 = match.group(0);
|
||||||
|
if (group0 != null && group0.isNotEmpty) {
|
||||||
|
if (start != match.start) {
|
||||||
|
_ResultMatch result1 = _ResultMatch();
|
||||||
|
result1.isUrl = false;
|
||||||
|
result1.text = text.substring(start, match.start);
|
||||||
|
resultMatches.add(result1);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ResultMatch result2 = _ResultMatch();
|
||||||
|
result2.isUrl = true;
|
||||||
|
result2.text = match.group(0)!;
|
||||||
|
resultMatches.add(result2);
|
||||||
|
start = match.end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start < text.length) {
|
||||||
|
_ResultMatch result1 = _ResultMatch();
|
||||||
|
result1.isUrl = false;
|
||||||
|
result1.text = text.substring(start);
|
||||||
|
resultMatches.add(result1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var result in resultMatches) {
|
||||||
|
if (result.isUrl) {
|
||||||
|
widgets.add(_LinkTextSpan(
|
||||||
|
replace: replace ?? result.text,
|
||||||
|
text: result.text,
|
||||||
|
style: style.copyWith(color: Colors.blue)));
|
||||||
|
} else {
|
||||||
|
widgets.add(TextSpan(
|
||||||
|
text: result.text,
|
||||||
|
style: style.copyWith(
|
||||||
|
color: isDarkMode ? Colors.white : Colors.black,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return RichText(
|
||||||
|
text: TextSpan(children: _getTextSpans(isDarkMode(context))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LinkTextSpan extends TextSpan {
|
||||||
|
_LinkTextSpan({TextStyle? style, required String text, String? replace})
|
||||||
|
: super(
|
||||||
|
style: style,
|
||||||
|
text: replace,
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
openUrl(text);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ResultMatch {
|
||||||
|
late bool isUrl;
|
||||||
|
late String text;
|
||||||
|
}
|
||||||
45
pubspec.lock
45
pubspec.lock
@@ -36,20 +36,15 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.1"
|
version: "1.3.1"
|
||||||
charts_common:
|
circle_chart:
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: charts_common
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "0.11.0"
|
|
||||||
charts_flutter:
|
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: charts_flutter
|
path: "."
|
||||||
url: "https://pub.dartlang.org"
|
ref: main
|
||||||
source: hosted
|
resolved-ref: f3e0088bb08c5d05473b1d568943f4f8732dd984
|
||||||
version: "0.11.0"
|
url: "https://github.com/LollipopKit/circle_chart"
|
||||||
|
source: git
|
||||||
|
version: "0.0.3"
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -86,7 +81,7 @@ packages:
|
|||||||
name: dio
|
name: dio
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.0"
|
version: "4.0.1"
|
||||||
extended_image:
|
extended_image:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -134,13 +129,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.4"
|
version: "1.0.4"
|
||||||
|
flutter_material_color_picker:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_material_color_picker
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.0+2"
|
||||||
flutter_plugin_android_lifecycle:
|
flutter_plugin_android_lifecycle:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: flutter_plugin_android_lifecycle
|
name: flutter_plugin_android_lifecycle
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.3"
|
version: "2.0.4"
|
||||||
flutter_staggered_animations:
|
flutter_staggered_animations:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -185,7 +187,7 @@ packages:
|
|||||||
name: http
|
name: http
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.13.3"
|
version: "0.13.4"
|
||||||
http_client_helper:
|
http_client_helper:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -200,13 +202,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.0"
|
version: "4.0.0"
|
||||||
intl:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: intl
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "0.17.0"
|
|
||||||
js:
|
js:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -318,7 +313,7 @@ packages:
|
|||||||
name: process
|
name: process
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.2.3"
|
version: "4.2.4"
|
||||||
provider:
|
provider:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -435,7 +430,7 @@ packages:
|
|||||||
name: uuid
|
name: uuid
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.4"
|
version: "3.0.5"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -449,7 +444,7 @@ packages:
|
|||||||
name: win32
|
name: win32
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.9"
|
version: "2.2.10"
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -44,8 +44,12 @@ dependencies:
|
|||||||
url: https://github.com/Countly/countly-sdk-flutter-bridge.git
|
url: https://github.com/Countly/countly-sdk-flutter-bridge.git
|
||||||
ref: master
|
ref: master
|
||||||
ssh2: ^2.2.3
|
ssh2: ^2.2.3
|
||||||
charts_flutter: ^0.11.0
|
|
||||||
logging: ^1.0.2
|
logging: ^1.0.2
|
||||||
|
flutter_material_color_picker: ^1.1.0+2
|
||||||
|
circle_chart:
|
||||||
|
git:
|
||||||
|
url: https://github.com/LollipopKit/circle_chart
|
||||||
|
ref: main
|
||||||
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|||||||
Reference in New Issue
Block a user