v0.0.1appearance
라이트, 다크 및 시스템 테마 모드를 구현하고 앱 재시작 시 설정을 유지하는 Flutter 패키지입니다.
라이트, 다크 및 시스템 테마 모드를 구현하고 앱 재시작 시 설정을 유지하는 Flutter 패키지입니다.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Flutter package that easily implement Light, Dark and System theme mode in your application and persists the theme mode on restart of the application.
🚀 Demo: Appearance


pubspec.yaml file:dependencies:
appearance: ^latest_version
import 'package:appearance/appearance.dart';
SharedPreferencesManager singleton for SharedPreference and add it before runApp() method.void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SharedPreferencesManager.instance.init();
runApp(const MyApp());
}
AppearanceState using keyword with.class _MyAppState extends State<MyApp> with AppearanceState { }
MaterialApp or CupertinoApp with BuildWithAppearanceBuildWithAppearance(
initial: ThemeMode.light, // optional : default value is [ThemeMode.system]
builder: (context) => MaterialApp()
);
MaterialAppBuildWithAppearance(
initial: ThemeMode.light, // optional : default value is [ThemeMode.system]
builder: (context) => MaterialApp(
title: 'Appearance (Material Example)',
themeMode: Appearance.of(context)?.mode,
theme: ThemeData(
brightness: Brightness.light,
),
darkTheme: ThemeData(
brightness: Brightness.dark,
),
home: const HomeMaterialPage(),
),
);
CupertinoAppBuildWithAppearance(
initial: ThemeMode.light, // optional : default value is [ThemeMode.system]
builder: (context) {
return CupertinoApp(
title: 'Appearance (Cupertino Example)',
theme: CupertinoThemeData(
brightness: Appearance.of(context)?.cupertinoBrightness!,
),
localizationsDelegates: const [
DefaultMaterialLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
home: HomeCupertinoPage(),
);
},
);
Light, Dark and System mode options to change theme of app.
Theme persistance: Saved theme is persisted using SharedPreferences on restart.
Auto Listen Theme Mode changes, without adding extra listener.
Material and Cupertino, both apps are supported.
ThemeMode of the app, by default its value is ThemeMode.systemYou can use the setMode method to change the theme mode of the app.
// sets theme mode to System
Appearance.of(context)?.setMode(ThemeMode.system),
// sets theme mode to Light
Appearance.of(context)?.setMode(ThemeMode.light),
// sets theme mode to Dark
Appearance.of(context)?.setMode(ThemeMode.dark),
// get active theme mode
Appearance.of(context)?.mode
// get active cupertino theme brightness
Appearance.of(context)?.cupertinoBrightness!,
Check out the example app in the example directory for both Material and Cupertino.
Feel free to contribute to this project.
If you found a bug or have a feature request, open an issue.
If you want to contribute, submit a pull request.
This project is LICENSED under the MIT License. Use it freely, but let's play nice and give credit where it's due!
I will be happy to answer any questions that you may have on this approach,
If you liked this package, don't forget to show some ❤️ by smashing the ⭐.
의존성 목록 4 개
{"sdk":"flutter"}>=2.1.1 <3.0.0{"sdk":"flutter"}^2.0.0사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗