패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소alihaider78222/appearance

외관

라이트, 다크 및 시스템 테마 모드를 구현하고 앱 재시작 시 설정을 유지하는 Flutter 패키지입니다.

외관 프로젝트 이미지
스타
5
포크
0
최근 푸시(UTC)
2024. 1. 4.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

appearance

Appearance

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

📱 Screenshots

Appearance Demo 1 Appearance Demo 2

🛠 Installation

  1. Add dependency to pubspec.yaml file:
    Get the latest version from the 'Installing' tab on pub.dev
dependencies:
  appearance: ^latest_version
  1. Import the package
import 'package:appearance/appearance.dart';

📘 How to use

  1. Initialize SharedPreferencesManager singleton for SharedPreference and add it before runApp() method.
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SharedPreferencesManager.instance.init();
  runApp(const MyApp());
}
  1. extend your root class with AppearanceState using keyword with.
class _MyAppState extends State<MyApp> with AppearanceState { }
  1. Wrap your MaterialApp or CupertinoApp with BuildWithAppearance
BuildWithAppearance(
    initial: ThemeMode.light, // optional : default value is [ThemeMode.system]
    builder: (context) => MaterialApp()
);
Using MaterialApp
BuildWithAppearance(
    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(),
    ),
);
Using CupertinoApp
BuildWithAppearance(
    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(),
        );
    },
);

🌟 Features

  • 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.

🧰 Parameters

  • initial: [optional]
    Set the initial ThemeMode of the app, by default its value is ThemeMode.system

Change Theme Mode

You 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 Theme Mode

 // get active theme mode
 Appearance.of(context)?.mode

Get Cupertino Theme brightness

 // get active cupertino theme brightness
 Appearance.of(context)?.cupertinoBrightness!,

💻 Example

Check out the example app in the example directory for both Material and Cupertino.

📝Contribution

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.

💳 License

This project is LICENSED under the MIT License. Use it freely, but let's play nice and give credit where it's due!

🎉 Conclusion

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 ⭐.

Ali Haider GitHub avatar
GitHub 작성자

Ali Haider ↗

Flutter | Ionic | Angular | Node.js | Full Stack Developer | Open For Work 💻👨‍💼

Kantar XTEL | ConvoIslamabad, Pakistan공식 웹사이트 ↗
언어Dart

분류

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 4 개

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗