mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
Init snippet page and store
This commit is contained in:
@@ -35,7 +35,7 @@ class PrivateKeyInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<PrivateKeyInfo>? getPrivateKeyInfoList(dynamic data) {
|
List<PrivateKeyInfo> getPrivateKeyInfoList(dynamic data) {
|
||||||
List<PrivateKeyInfo> ss = [];
|
List<PrivateKeyInfo> ss = [];
|
||||||
if (data is String) {
|
if (data is String) {
|
||||||
data = json.decode(data);
|
data = json.decode(data);
|
||||||
|
|||||||
30
lib/data/model/server/snippet.dart
Normal file
30
lib/data/model/server/snippet.dart
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class Snippet {
|
||||||
|
late String name;
|
||||||
|
late String script;
|
||||||
|
Snippet(this.name, this.script);
|
||||||
|
|
||||||
|
Snippet.fromJson(Map<String, dynamic> json) {
|
||||||
|
name = json['name'].toString();
|
||||||
|
script = json['script'].toString();
|
||||||
|
}
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final data = <String, dynamic>{};
|
||||||
|
data['name'] = name;
|
||||||
|
data['script'] = script;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Snippet> getSnippetList(dynamic data) {
|
||||||
|
List<Snippet> ss = [];
|
||||||
|
if (data is String) {
|
||||||
|
data = json.decode(data);
|
||||||
|
}
|
||||||
|
for (var t in data) {
|
||||||
|
ss.add(Snippet.fromJson(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ class PrivateKeyStore extends PersistentStore {
|
|||||||
|
|
||||||
List<PrivateKeyInfo> fetch() {
|
List<PrivateKeyInfo> fetch() {
|
||||||
return getPrivateKeyInfoList(
|
return getPrivateKeyInfoList(
|
||||||
json.decode(box.get('key', defaultValue: '[]')!))!;
|
json.decode(box.get('key', defaultValue: '[]')!));
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete(PrivateKeyInfo s) {
|
void delete(PrivateKeyInfo s) {
|
||||||
|
|||||||
33
lib/data/store/snippet.dart
Normal file
33
lib/data/store/snippet.dart
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:toolbox/core/persistant_store.dart';
|
||||||
|
import 'package:toolbox/data/model/server/snippet.dart';
|
||||||
|
|
||||||
|
class SnippetStore extends PersistentStore {
|
||||||
|
void put(Snippet snippet) {
|
||||||
|
final ss = fetch();
|
||||||
|
if (!have(snippet)) ss.add(snippet);
|
||||||
|
box.put('snippet', json.encode(ss));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Snippet> fetch() {
|
||||||
|
return getSnippetList(
|
||||||
|
json.decode(box.get('snippet', defaultValue: '[]')!));
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete(Snippet s) {
|
||||||
|
final ss = fetch();
|
||||||
|
ss.removeAt(index(s));
|
||||||
|
box.put('snippet', json.encode(ss));
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(Snippet old, Snippet newInfo) {
|
||||||
|
final ss = fetch();
|
||||||
|
ss[index(old)] = newInfo;
|
||||||
|
box.put('snippet', json.encode(ss));
|
||||||
|
}
|
||||||
|
|
||||||
|
int index(Snippet s) => fetch().indexWhere((e) => e.name == s.name);
|
||||||
|
|
||||||
|
bool have(Snippet s) => index(s) != -1;
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import 'package:toolbox/data/service/app.dart';
|
|||||||
import 'package:toolbox/data/store/private_key.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';
|
||||||
|
import 'package:toolbox/data/store/snippet.dart';
|
||||||
|
|
||||||
GetIt locator = GetIt.instance;
|
GetIt locator = GetIt.instance;
|
||||||
|
|
||||||
@@ -33,6 +34,10 @@ Future<void> setupLocatorForStores() async {
|
|||||||
final key = PrivateKeyStore();
|
final key = PrivateKeyStore();
|
||||||
await key.init(boxName: 'key');
|
await key.init(boxName: 'key');
|
||||||
locator.registerSingleton(key);
|
locator.registerSingleton(key);
|
||||||
|
|
||||||
|
final snippet = SnippetStore();
|
||||||
|
await snippet.init(boxName: 'snippet');
|
||||||
|
locator.registerSingleton(snippet);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setupLocator() async {
|
Future<void> setupLocator() async {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
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:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
|
import 'package:toolbox/core/analysis.dart';
|
||||||
|
import 'package:toolbox/core/build_mode.dart';
|
||||||
import 'package:toolbox/core/route.dart';
|
import 'package:toolbox/core/route.dart';
|
||||||
import 'package:toolbox/core/update.dart';
|
import 'package:toolbox/core/update.dart';
|
||||||
import 'package:toolbox/core/utils.dart';
|
import 'package:toolbox/core/utils.dart';
|
||||||
@@ -90,8 +92,13 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
applicationIcon: _buildIcon(),
|
applicationIcon: _buildIcon(),
|
||||||
aboutBoxChildren: const [
|
aboutBoxChildren: const [
|
||||||
UrlText(
|
UrlText(
|
||||||
text: '\nMade with ❤️ by https://github.com/LollipopKit', replace: 'LollipopKit'),
|
text: '\nMade with ❤️ by https://github.com/LollipopKit',
|
||||||
UrlText(text: '\nThanks https://github.com/RainSunMe for participating in the test.\n\nAll rights reserved.', replace: 'RainSunMe',),
|
replace: 'LollipopKit'),
|
||||||
|
UrlText(
|
||||||
|
text:
|
||||||
|
'\nThanks https://github.com/RainSunMe for participating in the test.\n\nAll rights reserved.',
|
||||||
|
replace: 'RainSunMe',
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -118,5 +125,6 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
await GetIt.I.allReady();
|
await GetIt.I.allReady();
|
||||||
await locator<ServerProvider>().loadLocalData();
|
await locator<ServerProvider>().loadLocalData();
|
||||||
await doUpdate(context);
|
await doUpdate(context);
|
||||||
|
await Analysis.init(BuildMode.isDebug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
lib/view/page/snippet/edit.dart
Normal file
17
lib/view/page/snippet/edit.dart
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class SnappetEditPage extends StatefulWidget {
|
||||||
|
const SnappetEditPage({ Key? key }) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SnappetEditPageState createState() => _SnappetEditPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SnappetEditPageState extends State<SnappetEditPage> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
lib/view/page/snippet/list.dart
Normal file
17
lib/view/page/snippet/list.dart
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class SnappetListPage extends StatefulWidget {
|
||||||
|
const SnappetListPage({ Key? key }) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SnappetListPageState createState() => _SnappetListPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SnappetListPageState extends State<SnappetListPage> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user