mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-17 09:54:19 +01:00
add some config to project and change come simple ui
This commit is contained in:
161
lib/main.dart
161
lib/main.dart
@@ -5,6 +5,8 @@ import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/provider/web_provider.dart';
|
||||
import 'package:nowser/router/index/index_router.dart';
|
||||
import 'package:nowser/router/web_tabs_select/web_tabs_select_router.dart';
|
||||
@@ -12,15 +14,28 @@ import 'package:provider/provider.dart';
|
||||
import 'package:receive_intent/receive_intent.dart' as receiveIntent;
|
||||
|
||||
import 'const/base.dart';
|
||||
import 'const/colors.dart';
|
||||
import 'const/router_path.dart';
|
||||
import 'generated/l10n.dart';
|
||||
import 'provider/data_util.dart';
|
||||
import 'provider/setting_provider.dart';
|
||||
import 'util/colors_util.dart';
|
||||
|
||||
late WebProvider webProvider;
|
||||
|
||||
late SettingProvider settingProvider;
|
||||
|
||||
late Map<String, WidgetBuilder> routes;
|
||||
|
||||
void main() {
|
||||
Future<void> main() async {
|
||||
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
var dataUtilTask = DataUtil.getInstance();
|
||||
var dataFutureResultList = await Future.wait([dataUtilTask]);
|
||||
|
||||
var settingTask = SettingProvider.getInstance();
|
||||
var futureResultList = await Future.wait([settingTask]);
|
||||
settingProvider = futureResultList[0] as SettingProvider;
|
||||
webProvider = WebProvider();
|
||||
|
||||
runApp(MyApp());
|
||||
@@ -84,17 +99,161 @@ class _MyApp extends State<MyApp> {
|
||||
}
|
||||
|
||||
ThemeData getLightTheme() {
|
||||
Color color500 = _getMainColor();
|
||||
MaterialColor themeColor = ColorList.getThemeColor(color500.value);
|
||||
|
||||
Color mainTextColor = Colors.black;
|
||||
Color hintColor = Colors.grey;
|
||||
var scaffoldBackgroundColor = Colors.grey[100];
|
||||
Color cardColor = Colors.white;
|
||||
|
||||
if (settingProvider.mainFontColor != null) {
|
||||
mainTextColor = Color(settingProvider.mainFontColor!);
|
||||
}
|
||||
if (settingProvider.hintFontColor != null) {
|
||||
hintColor = Color(settingProvider.hintFontColor!);
|
||||
}
|
||||
if (settingProvider.cardColor != null) {
|
||||
cardColor = Color(settingProvider.cardColor!);
|
||||
}
|
||||
|
||||
double baseFontSize = settingProvider.fontSize;
|
||||
|
||||
var textTheme = TextTheme(
|
||||
bodyLarge: TextStyle(fontSize: baseFontSize + 2, color: mainTextColor),
|
||||
bodyMedium: TextStyle(fontSize: baseFontSize, color: mainTextColor),
|
||||
bodySmall: TextStyle(fontSize: baseFontSize - 2, color: mainTextColor),
|
||||
);
|
||||
var titleTextStyle = TextStyle(
|
||||
color: mainTextColor,
|
||||
);
|
||||
|
||||
if (settingProvider.fontFamily != null) {
|
||||
textTheme =
|
||||
GoogleFonts.getTextTheme(settingProvider.fontFamily!, textTheme);
|
||||
titleTextStyle = GoogleFonts.getFont(settingProvider.fontFamily!,
|
||||
textStyle: titleTextStyle);
|
||||
}
|
||||
|
||||
return ThemeData(
|
||||
platform: TargetPlatform.iOS,
|
||||
primarySwatch: themeColor,
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: themeColor[500]!,
|
||||
brightness: Brightness.light,
|
||||
),
|
||||
// scaffoldBackgroundColor: Base.SCAFFOLD_BACKGROUND_COLOR,
|
||||
// scaffoldBackgroundColor: Colors.grey[100],
|
||||
scaffoldBackgroundColor: scaffoldBackgroundColor,
|
||||
primaryColor: themeColor[500],
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: cardColor,
|
||||
titleTextStyle: titleTextStyle,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
),
|
||||
dividerColor: ColorsUtil.hexToColor("#DFE1EB"),
|
||||
cardColor: cardColor,
|
||||
// dividerColor: Colors.grey[200],
|
||||
// indicatorColor: ColorsUtil.hexToColor("#818181"),
|
||||
textTheme: textTheme,
|
||||
hintColor: hintColor,
|
||||
buttonTheme: ButtonThemeData(),
|
||||
shadowColor: Colors.black.withOpacity(0.2),
|
||||
tabBarTheme: TabBarTheme(
|
||||
indicatorColor: Colors.white,
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
dividerHeight: 0,
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.grey[200],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ThemeData getDarkTheme() {
|
||||
Color color500 = _getMainColor();
|
||||
MaterialColor themeColor = ColorList.getThemeColor(color500.value);
|
||||
|
||||
Color? mainTextColor;
|
||||
// Color? topFontColor = Colors.white;
|
||||
Color? topFontColor = Colors.grey[200];
|
||||
Color hintColor = Colors.grey;
|
||||
var scaffoldBackgroundColor = Color.fromARGB(255, 40, 40, 40);
|
||||
Color cardColor = Colors.black;
|
||||
|
||||
if (settingProvider.mainFontColor != null) {
|
||||
mainTextColor = Color(settingProvider.mainFontColor!);
|
||||
}
|
||||
if (settingProvider.hintFontColor != null) {
|
||||
hintColor = Color(settingProvider.hintFontColor!);
|
||||
}
|
||||
if (settingProvider.cardColor != null) {
|
||||
cardColor = Color(settingProvider.cardColor!);
|
||||
}
|
||||
|
||||
double baseFontSize = settingProvider.fontSize;
|
||||
|
||||
var textTheme = TextTheme(
|
||||
bodyLarge: TextStyle(fontSize: baseFontSize + 2, color: mainTextColor),
|
||||
bodyMedium: TextStyle(fontSize: baseFontSize, color: mainTextColor),
|
||||
bodySmall: TextStyle(fontSize: baseFontSize - 2, color: mainTextColor),
|
||||
);
|
||||
var titleTextStyle = TextStyle(
|
||||
color: topFontColor,
|
||||
// color: Colors.black,
|
||||
);
|
||||
|
||||
if (settingProvider.fontFamily != null) {
|
||||
textTheme =
|
||||
GoogleFonts.getTextTheme(settingProvider.fontFamily!, textTheme);
|
||||
titleTextStyle = GoogleFonts.getFont(settingProvider.fontFamily!,
|
||||
textStyle: titleTextStyle);
|
||||
}
|
||||
|
||||
if (StringUtil.isNotBlank(settingProvider.backgroundImage)) {
|
||||
scaffoldBackgroundColor = Colors.transparent;
|
||||
cardColor = cardColor.withOpacity(0.6);
|
||||
}
|
||||
|
||||
return ThemeData(
|
||||
platform: TargetPlatform.iOS,
|
||||
primarySwatch: themeColor,
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: themeColor[500]!,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
scaffoldBackgroundColor: scaffoldBackgroundColor,
|
||||
primaryColor: themeColor[500],
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: cardColor,
|
||||
titleTextStyle: titleTextStyle,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
),
|
||||
dividerColor: Colors.grey[200],
|
||||
cardColor: cardColor,
|
||||
textTheme: textTheme,
|
||||
hintColor: hintColor,
|
||||
shadowColor: Colors.white.withOpacity(0.3),
|
||||
tabBarTheme: TabBarTheme(
|
||||
indicatorColor: Colors.white,
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
dividerHeight: 0,
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.grey[200],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getMainColor() {
|
||||
Color color500 = const Color(0xff519495);
|
||||
if (settingProvider.themeColor != null) {
|
||||
color500 = Color(settingProvider.themeColor!);
|
||||
}
|
||||
return color500;
|
||||
}
|
||||
|
||||
|
||||
// class MyApp extends StatelessWidget {
|
||||
// const MyApp({super.key});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user