#156 opt.: show error of settings json

This commit is contained in:
lollipopkit
2023-09-07 16:41:38 +08:00
parent 459b647b68
commit 567f1442f5
7 changed files with 63 additions and 46 deletions

View File

@@ -33,6 +33,14 @@ class MyApp extends StatelessWidget {
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: primaryColor,
/// After upgrading to flutter 3.13,
/// the shadow color of the drawer is white (maybe a bug).
/// TODO: remember to remove it after the bug is fixed.
drawerTheme: const DrawerThemeData(
backgroundColor: Colors.black,
shadowColor: Colors.black12,
),
);
return MaterialApp(
@@ -57,8 +65,6 @@ class MyApp extends StatelessWidget {
ThemeData _getAmoledTheme(ThemeData darkTheme) => darkTheme.copyWith(
scaffoldBackgroundColor: Colors.black,
dialogBackgroundColor: Colors.black,
drawerTheme: const DrawerThemeData(
backgroundColor: Colors.black, shadowColor: Colors.black),
appBarTheme: const AppBarTheme(backgroundColor: Colors.black),
dialogTheme: const DialogTheme(backgroundColor: Colors.black),
bottomSheetTheme:

View File

@@ -2,8 +2,8 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 526;
static const String engine = "3.13.1";
static const String buildAt = "2023-09-05 21:15:22.219124";
static const int modifications = 2;
static const int build = 529;
static const String engine = "3.13.2";
static const String buildAt = "2023-09-06 21:16:27.707712";
static const int modifications = 4;
}

View File

@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'package:after_layout/after_layout.dart';
import 'package:code_text_field/code_text_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
@@ -44,14 +43,16 @@ class EditorPage extends StatefulWidget {
_EditorPageState createState() => _EditorPageState();
}
class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
late CodeController _controller;
late final _focusNode = FocusNode();
class _EditorPageState extends State<EditorPage> {
final _focusNode = FocusNode();
final _setting = locator<SettingStore>();
late CodeController _controller;
late Map<String, TextStyle> _codeTheme;
late S _s;
late String? _langCode;
late TextStyle _textStyle;
late final _textStyle = TextStyle(fontSize: _setting.editorFontSize.fetch());
String? _langCode;
@override
void initState() {
@@ -62,7 +63,16 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
_controller = CodeController(
language: suffix2HighlightMap[_langCode],
);
_textStyle = TextStyle(fontSize: _setting.editorFontSize.fetch());
/// TODO: This is a temporary solution to avoid the loading stuck
Future.delayed(const Duration(milliseconds: 377)).then((value) async {
if (widget.path != null) {
final code = await File(widget.path!).readAsString();
_controller.text = code;
} else if (widget.text != null) {
_controller.text = widget.text!;
}
});
}
@override
@@ -115,7 +125,7 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
return CustomAppBar(
centerTitle: true,
title: TwoLineText(
up: widget.title ?? getFileName(widget.path) ?? '',
up: widget.title ?? getFileName(widget.path) ?? _s.unknown,
down: _s.editor,
),
actions: [
@@ -156,16 +166,4 @@ class _EditorPageState extends State<EditorPage> with AfterLayoutMixin {
),
));
}
@override
FutureOr<void> afterFirstLayout(BuildContext context) async {
/// TODO: This is a temporary solution to avoid the loading stuck
await Future.delayed(const Duration(milliseconds: 377));
if (widget.path != null) {
final code = await File(widget.path!).readAsString();
_controller.text = code;
} else if (widget.text != null) {
_controller.text = widget.text!;
}
}
}

View File

@@ -370,6 +370,15 @@ class _HomePageState extends State<HomePage>
if (result == null) {
return;
}
_setting.box.putAll(json.decode(result) as Map<String, dynamic>);
try {
final newSettings = json.decode(result) as Map<String, dynamic>;
_setting.box.putAll(newSettings);
} catch (e) {
showRoundDialog(
context: context,
title: Text(_s.error),
child: Text('${_s.save}:\n$e'),
);
}
}
}

View File

@@ -320,7 +320,11 @@ class _ServerDetailPageState extends State<ServerDetailPage>
style: textSize11,
textScaleFactor: _textFactor,
),
Text(disk.path, style: textSize11, textScaleFactor: _textFactor,)
Text(
disk.path,
style: textSize11,
textScaleFactor: _textFactor,
)
],
),
_buildProgress(disk.usedPercent.toDouble())