add app theme extension

pull/1/head
张萌 3 years ago
parent 3af5a63b4c
commit 62c67abfe0

@ -93,5 +93,7 @@
<false/>
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
</dict>
</plist>

@ -6,6 +6,15 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
class AppTheme {
static ThemeData get theme {
return ThemeData(primarySwatch: Colors.blue).copyWith(
extensions: <ThemeExtension<dynamic>>[
MyAppStyle(
mainColor: Colors.blue,
bodyText3: TextStyle(
fontSize: 30.sp,
color: const Color(0xFF333333),
),
)
],
progressIndicatorTheme:
ProgressIndicatorThemeData(color: Color(0xFFFFD000)),
primaryColor: Color(0xFFFFD000),
@ -175,3 +184,32 @@ class SystemStyle {
);
}
}
@immutable
class MyAppStyle extends ThemeExtension<MyAppStyle> {
final TextStyle? bodyText3;
final Color? mainColor;
@override
MyAppStyle copyWith({Color? mainColor, TextStyle? bodyText3}) {
return MyAppStyle(
mainColor: mainColor ?? this.mainColor,
bodyText3: bodyText3 ?? this.bodyText3);
}
@override
ThemeExtension<MyAppStyle> lerp(ThemeExtension<MyAppStyle>? other, double t) {
if (other is! MyAppStyle) {
return this;
}
return MyAppStyle(
mainColor: Color.lerp(mainColor, other.mainColor, t),
bodyText3: TextStyle.lerp(bodyText3, other.bodyText3, t),
);
}
const MyAppStyle({
this.bodyText3,
this.mainColor,
});
}

@ -1,3 +1,5 @@
import 'package:aku_new_community/constants/app_theme.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
@ -11,7 +13,12 @@ class UserTool {
static AppProvider get appProvider =>
Provider.of<AppProvider>(Get.context!, listen: false);
static DataProvider get dataProvider =>
Provider.of<DataProvider>(Get.context!, listen: false);
static MyAppStyle get myAppStyle =>
Theme.of(Get.context!).extension<MyAppStyle>()!;
UserTool();
}

Loading…
Cancel
Save