自习室优化ok
This commit is contained in:
27
lib/global/config.dart
Normal file
27
lib/global/config.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
class Config {
|
||||
///获取环境
|
||||
static String getEnv() {
|
||||
const env = String.fromEnvironment('ENV', defaultValue: 'dev');
|
||||
return env;
|
||||
}
|
||||
|
||||
///获取接口地址
|
||||
static String baseUrl() {
|
||||
if (getEnv() == 'dev') {
|
||||
return 'https://xueguang.test.tuzuu.com/api';
|
||||
} else {
|
||||
return 'https://xueguang.test.tuzuu.com/api';
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取websocket地址
|
||||
static String wsUrl() {
|
||||
return "wss://xueguang.test.tuzuu.com/ws";
|
||||
}
|
||||
|
||||
///网页域名地址
|
||||
static String get webUrl => "http://xueguang.test.tuzuu.com";
|
||||
|
||||
///声网APPid
|
||||
static String get swAppId => "011c2fd2e1854511a80c1aebded4eee7";
|
||||
}
|
||||
33
lib/global/event_bus.dart
Normal file
33
lib/global/event_bus.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'dart:async';
|
||||
|
||||
/// 全局事件总线
|
||||
class EventBus {
|
||||
EventBus._();
|
||||
|
||||
static final _instance = EventBus._();
|
||||
|
||||
factory EventBus() => _instance;
|
||||
|
||||
|
||||
// StreamController,广播模式可以让多个地方监听
|
||||
final StreamController<GlobalEvent> _controller = StreamController.broadcast();
|
||||
|
||||
/// 发送事件
|
||||
void fire(GlobalEvent event) {
|
||||
_controller.add(event);
|
||||
}
|
||||
|
||||
/// 监听事件
|
||||
Stream<GlobalEvent> get stream => _controller.stream;
|
||||
|
||||
/// 关闭流(一般应用生命周期结束时调用)
|
||||
void dispose() {
|
||||
_controller.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// 事件类型枚举
|
||||
enum GlobalEvent {
|
||||
unauthorized, // 401 需要重新登录
|
||||
// 以后可以扩展其他事件
|
||||
}
|
||||
35
lib/global/theme/base/app_colors_base.dart
Normal file
35
lib/global/theme/base/app_colors_base.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'dart:ui';
|
||||
|
||||
abstract class AppColorsBase {
|
||||
/// 品牌主色
|
||||
Color get primary;
|
||||
|
||||
// 灰度
|
||||
Color get textPrimary;
|
||||
|
||||
Color get textSecondary;
|
||||
|
||||
Color get textTertiary;
|
||||
|
||||
// 状态颜色
|
||||
Color get success;
|
||||
|
||||
Color get warning;
|
||||
|
||||
Color get info;
|
||||
|
||||
Color get danger;
|
||||
|
||||
|
||||
// 容器色
|
||||
Color get surfaceContainerLowest;
|
||||
|
||||
Color get surfaceContainerLow;
|
||||
|
||||
Color get surfaceContainer;
|
||||
|
||||
Color get surfaceContainerHigh; //白色卡片 / item
|
||||
|
||||
//阴影颜色
|
||||
Color get shadow;
|
||||
}
|
||||
54
lib/global/theme/base/app_text_style.dart
Normal file
54
lib/global/theme/base/app_text_style.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'app_colors_base.dart'; // 假设你之前定义了 AppColorsBase
|
||||
|
||||
TextTheme buildTextTheme(AppColorsBase colors) {
|
||||
return TextTheme(
|
||||
// 标题层级
|
||||
titleLarge: TextStyle(
|
||||
fontSize: 22, // 比正文大6
|
||||
fontWeight: FontWeight.w700,
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
titleMedium: TextStyle(
|
||||
fontSize: 20, // 比正文大4
|
||||
fontWeight: FontWeight.w700,
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
titleSmall: TextStyle(
|
||||
fontSize: 18, // 比正文大2
|
||||
fontWeight: FontWeight.w700,
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
|
||||
// 正文字体
|
||||
bodyLarge: TextStyle(
|
||||
fontSize: 18, // 稍大正文
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
bodyMedium: TextStyle(
|
||||
fontSize: 16, // 正文标准
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
bodySmall: TextStyle(
|
||||
fontSize: 14, // 辅助正文
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
|
||||
// 标签/提示文字
|
||||
labelLarge: TextStyle(
|
||||
fontSize: 14, // 比正文小一点
|
||||
fontWeight: FontWeight.w500,
|
||||
color: colors.textSecondary,
|
||||
),
|
||||
labelMedium: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: colors.textSecondary,
|
||||
),
|
||||
labelSmall: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: colors.textSecondary,
|
||||
),
|
||||
);
|
||||
}
|
||||
45
lib/global/theme/base/app_theme_ext.dart
Normal file
45
lib/global/theme/base/app_theme_ext.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_colors_base.dart';
|
||||
|
||||
@immutable
|
||||
class AppThemeExtension extends ThemeExtension<AppThemeExtension> {
|
||||
final AppColorsBase baseTheme;
|
||||
|
||||
const AppThemeExtension({required this.baseTheme});
|
||||
|
||||
@override
|
||||
ThemeExtension<AppThemeExtension> copyWith({
|
||||
AppColorsBase? baseTheme,
|
||||
}) {
|
||||
return AppThemeExtension(
|
||||
baseTheme: baseTheme ?? this.baseTheme,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AppThemeExtension lerp(AppThemeExtension? other, double t) {
|
||||
if (other is! AppThemeExtension) return this;
|
||||
return t < 0.5 ? this : other; // 或者 this/base 混合逻辑
|
||||
}
|
||||
}
|
||||
|
||||
extension AppThemeExt on BuildContext {
|
||||
AppThemeExtension get themeEx => Theme.of(this).extension<AppThemeExtension>()!;
|
||||
|
||||
///主题
|
||||
Color get success => themeEx.baseTheme.success;
|
||||
|
||||
Color get warning => themeEx.baseTheme.warning;
|
||||
|
||||
Color get danger => themeEx.baseTheme.danger;
|
||||
|
||||
Color get info => themeEx.baseTheme.info;
|
||||
|
||||
//字体灰度
|
||||
Color get textSecondary => themeEx.baseTheme.textSecondary;
|
||||
|
||||
Color get textTertiary => themeEx.baseTheme.textTertiary;
|
||||
|
||||
double get pagePadding => 12;
|
||||
}
|
||||
41
lib/global/theme/theme.dart
Normal file
41
lib/global/theme/theme.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'base/app_colors_base.dart';
|
||||
import 'base/app_text_style.dart';
|
||||
import 'base/app_theme_ext.dart';
|
||||
|
||||
export 'themes/light_theme.dart';
|
||||
export 'base/app_theme_ext.dart';
|
||||
|
||||
class AppTheme {
|
||||
static ThemeData createTheme(AppColorsBase themeBase) {
|
||||
final textTheme = buildTextTheme(themeBase);
|
||||
return ThemeData(
|
||||
useMaterial3: true,
|
||||
fontFamily: "资源圆体",
|
||||
primaryColor: themeBase.primary,
|
||||
scaffoldBackgroundColor: themeBase.surfaceContainerHigh,
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: themeBase.primary,
|
||||
brightness: Brightness.light,
|
||||
onSurfaceVariant: themeBase.textSecondary,
|
||||
//背景色
|
||||
surfaceContainerHigh: themeBase.surfaceContainerHigh,
|
||||
surfaceContainer: themeBase.surfaceContainer,
|
||||
surfaceContainerLow: themeBase.surfaceContainerLow,
|
||||
surfaceContainerLowest: themeBase.surfaceContainerLowest,
|
||||
//阴影
|
||||
shadow: themeBase.shadow,
|
||||
),
|
||||
textTheme: textTheme,
|
||||
extensions: [AppThemeExtension(baseTheme: themeBase)],
|
||||
// pageTransitionsTheme: const PageTransitionsTheme(),
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: Colors.white,
|
||||
titleTextStyle: textTheme.titleMedium,
|
||||
scrolledUnderElevation: 0,
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
46
lib/global/theme/themes/light_theme.dart
Normal file
46
lib/global/theme/themes/light_theme.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../base/app_colors_base.dart';
|
||||
|
||||
class LightTheme extends AppColorsBase {
|
||||
@override
|
||||
Color get primary => const Color(0xff615fff);
|
||||
|
||||
@override
|
||||
Color get textPrimary => const Color(0xff222932);
|
||||
|
||||
@override
|
||||
Color get textSecondary => const Color(0xffA6B0BE);
|
||||
|
||||
@override
|
||||
Color get textTertiary => const Color(0xffC7CDD5);
|
||||
|
||||
@override
|
||||
Color get success => const Color(0xff00D4B5);
|
||||
|
||||
@override
|
||||
Color get warning => const Color(0xffFF9200);
|
||||
|
||||
@override
|
||||
Color get info => const Color(0xFFEEEEEE);
|
||||
|
||||
@override
|
||||
Color get danger => const Color(0xffFF4900);
|
||||
|
||||
@override
|
||||
Color get surfaceContainerLowest => Color(0xffE0E0E0);
|
||||
|
||||
@override
|
||||
Color get surfaceContainerLow => Color(0xffF0F0F0);
|
||||
|
||||
@override
|
||||
Color get surfaceContainer => Color(0xfff7f9fa);
|
||||
|
||||
@override
|
||||
Color get surfaceContainerHigh => Color(0xffFFFFFF);
|
||||
|
||||
@override
|
||||
Color get shadow => const Color.fromRGBO(0, 0, 0, 0.1);
|
||||
}
|
||||
Reference in New Issue
Block a user