mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
Completely apply theme to app
This commit is contained in:
48
lib/app.dart
48
lib/app.dart
@@ -6,6 +6,21 @@ import 'package:toolbox/view/page/home.dart';
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
MaterialStateProperty<Color?> getMaterialStateColor(Color primaryColor) {
|
||||
return MaterialStateProperty.resolveWith((states) {
|
||||
const Set<MaterialState> interactiveStates = <MaterialState>{
|
||||
MaterialState.pressed,
|
||||
MaterialState.hovered,
|
||||
MaterialState.focused,
|
||||
MaterialState.selected
|
||||
};
|
||||
if (states.any(interactiveStates.contains)) {
|
||||
return primaryColor;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -13,6 +28,7 @@ class MyApp extends StatelessWidget {
|
||||
valueListenable: locator<SettingStore>().primaryColor.listenable(),
|
||||
builder: (_, value, __) {
|
||||
final primaryColor = Color(value);
|
||||
final textStyle = TextStyle(color: primaryColor);
|
||||
return MaterialApp(
|
||||
title: 'ToolBox',
|
||||
theme: ThemeData(
|
||||
@@ -22,8 +38,38 @@ class MyApp extends StatelessWidget {
|
||||
FloatingActionButtonThemeData(backgroundColor: primaryColor),
|
||||
iconTheme: IconThemeData(color: primaryColor),
|
||||
primaryIconTheme: IconThemeData(color: primaryColor),
|
||||
switchTheme: SwitchThemeData(
|
||||
thumbColor: getMaterialStateColor(primaryColor),
|
||||
trackColor:
|
||||
getMaterialStateColor(primaryColor.withOpacity(0.7)),
|
||||
),
|
||||
buttonTheme: ButtonThemeData(splashColor: primaryColor),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
labelStyle: textStyle,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor))),
|
||||
radioTheme: RadioThemeData(
|
||||
fillColor: getMaterialStateColor(primaryColor)),
|
||||
),
|
||||
darkTheme: ThemeData.dark().copyWith(primaryColor: primaryColor),
|
||||
darkTheme: ThemeData.dark().copyWith(
|
||||
primaryColor: primaryColor,
|
||||
appBarTheme: AppBarTheme(backgroundColor: primaryColor),
|
||||
floatingActionButtonTheme:
|
||||
FloatingActionButtonThemeData(backgroundColor: primaryColor),
|
||||
iconTheme: IconThemeData(color: primaryColor),
|
||||
primaryIconTheme: IconThemeData(color: primaryColor),
|
||||
switchTheme: SwitchThemeData(
|
||||
thumbColor: getMaterialStateColor(primaryColor),
|
||||
trackColor:
|
||||
getMaterialStateColor(primaryColor.withOpacity(0.7)),
|
||||
),
|
||||
buttonTheme: ButtonThemeData(splashColor: primaryColor),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
labelStyle: textStyle,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor))),
|
||||
radioTheme: RadioThemeData(
|
||||
fillColor: getMaterialStateColor(primaryColor))),
|
||||
home: MyHomePage(primaryColor: primaryColor),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -111,7 +111,16 @@ class ServerProvider extends BusyProvider {
|
||||
final time2 = DateTime.now();
|
||||
logger.info(
|
||||
'Connected to [${info.name}] in [${time2.difference(time1).toString()}].');
|
||||
} else {
|
||||
try {
|
||||
await client.execute('ls');
|
||||
} catch (e) {
|
||||
await client.connect();
|
||||
logger.warning('[${info.name}] has error: $e \nTrying to reconnect.');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
final cpu = await client.execute(
|
||||
"top -bn1 | grep load | awk '{printf \"%.2f\", \$(NF-2)}'") ??
|
||||
'0';
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
Color primaryColor = Color(locator<SettingStore>().primaryColor.fetch()!);
|
||||
|
||||
class DynamicColor {
|
||||
/// 白天模式显示的颜色
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
|
||||
class ConvertPage extends StatefulWidget {
|
||||
const ConvertPage({Key? key}) : super(key: key);
|
||||
@@ -103,6 +104,8 @@ class _ConvertPageState extends State<ConvertPage>
|
||||
return Card(
|
||||
child: ExpansionTile(
|
||||
leading: TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all(primaryColor)),
|
||||
child: SizedBox(
|
||||
width: _media.size.width * 0.3,
|
||||
child: Row(
|
||||
@@ -115,11 +118,15 @@ class _ConvertPageState extends State<ConvertPage>
|
||||
_textEditingControllerResult.text = temp;
|
||||
},
|
||||
),
|
||||
title: SizedBox(
|
||||
title: const SizedBox(),
|
||||
trailing: SizedBox(
|
||||
width: _media.size.width * 0.4,
|
||||
child: Text(
|
||||
_typeOption[_typeOptionIndex],
|
||||
style: const TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500),
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: primaryColor),
|
||||
),
|
||||
),
|
||||
children: _typeOption
|
||||
|
||||
@@ -102,18 +102,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
Widget _buildIcon() {
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 60, maxWidth: 60),
|
||||
child: Stack(
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
height: 37,
|
||||
width: 37,
|
||||
),
|
||||
),
|
||||
Image.asset('assets/app_icon.jpg'),
|
||||
],
|
||||
),
|
||||
child: Image.asset('assets/app_icon.jpg'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ 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';
|
||||
import 'package:toolbox/view/widget/input_decoration.dart';
|
||||
|
||||
class PrivateKeyEditPage extends StatefulWidget {
|
||||
const PrivateKeyEditPage({Key? key, this.info}) : super(key: key);
|
||||
@@ -46,7 +47,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
TextField(
|
||||
controller: nameController,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: _buildDecoration('Name', icon: Icons.info),
|
||||
decoration: buildDecoration('Name', icon: Icons.info),
|
||||
),
|
||||
TextField(
|
||||
controller: keyController,
|
||||
@@ -54,14 +55,14 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
minLines: 3,
|
||||
maxLines: 10,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: _buildDecoration('Private Key', icon: Icons.vpn_key),
|
||||
decoration: buildDecoration('Private Key', icon: Icons.vpn_key),
|
||||
),
|
||||
TextField(
|
||||
controller: pwdController,
|
||||
autocorrect: false,
|
||||
keyboardType: TextInputType.text,
|
||||
obscureText: true,
|
||||
decoration: _buildDecoration('Password', icon: Icons.password),
|
||||
decoration: buildDecoration('Password', icon: Icons.password),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -81,12 +82,6 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -2,6 +2,7 @@ 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/data/res/color.dart';
|
||||
import 'package:toolbox/view/page/private_key/edit.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
|
||||
@@ -13,6 +14,7 @@ class StoredPrivateKeysPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
|
||||
final _textStyle = TextStyle(color: primaryColor);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -40,7 +42,10 @@ class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
|
||||
PrivateKeyEditPage(info: key.infos[idx]),
|
||||
'private key edit page')
|
||||
.go(context),
|
||||
child: const Text('Edit'))
|
||||
child: Text(
|
||||
'Edit',
|
||||
style: _textStyle,
|
||||
))
|
||||
],
|
||||
));
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:toolbox/data/provider/private_key.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/page/private_key/edit.dart';
|
||||
import 'package:toolbox/view/widget/input_decoration.dart';
|
||||
|
||||
class ServerEditPage extends StatefulWidget {
|
||||
const ServerEditPage({Key? key, this.spi}) : super(key: key);
|
||||
@@ -61,25 +62,25 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
TextField(
|
||||
controller: nameController,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: _buildDecoration('Name', icon: Icons.info),
|
||||
decoration: buildDecoration('Name', icon: Icons.info),
|
||||
),
|
||||
TextField(
|
||||
controller: ipController,
|
||||
keyboardType: TextInputType.text,
|
||||
autocorrect: false,
|
||||
decoration: _buildDecoration('Host', icon: Icons.storage),
|
||||
decoration: buildDecoration('Host', icon: Icons.storage),
|
||||
),
|
||||
TextField(
|
||||
controller: portController,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration:
|
||||
_buildDecoration('Port', icon: Icons.format_list_numbered),
|
||||
buildDecoration('Port', icon: Icons.format_list_numbered),
|
||||
),
|
||||
TextField(
|
||||
controller: usernameController,
|
||||
keyboardType: TextInputType.text,
|
||||
autocorrect: false,
|
||||
decoration: _buildDecoration('User', icon: Icons.account_box),
|
||||
decoration: buildDecoration('User', icon: Icons.account_box),
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
Row(
|
||||
@@ -95,7 +96,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
controller: passwordController,
|
||||
obscureText: true,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: _buildDecoration('Pwd', icon: Icons.password),
|
||||
decoration: buildDecoration('Pwd', icon: Icons.password),
|
||||
onSubmitted: (_) => {},
|
||||
)
|
||||
: const SizedBox(),
|
||||
|
||||
13
lib/view/widget/input_decoration.dart
Normal file
13
lib/view/widget/input_decoration.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
|
||||
InputDecoration buildDecoration(String label,
|
||||
{TextStyle? textStyle, IconData? icon}) {
|
||||
return InputDecoration(
|
||||
labelText: label,
|
||||
labelStyle: textStyle,
|
||||
icon: Icon(
|
||||
icon,
|
||||
color: primaryColor,
|
||||
));
|
||||
}
|
||||
Reference in New Issue
Block a user