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

theme_mode_builder 표지
패키지 상세v2.0.0

theme_mode_builder

앱에서 테마를 처리하고 공유 설정을 사용하여 장치에 저장하는 Flutter 패키지

AndroidiOSmacOSWindowsLinux
30일 다운로드
64
좋아요
24
Pub 점수
160

패키지 설치

flutter pub add theme_mode_builder

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

앱에서 테마 관리를 단순화하는 플러터 패키지로, 밝은 모드와 어두운 모드 간의 원활한 전환을 가능하게 합니다. 공유 설정과 통합되어 사용자의 테마 선택을 앱 재시작 후에도 유지하여 일관된 경험을 보장합니다. 봐야 할 코드 없이 테마 커스터마이징을 쉽게 구현하고자 하는 개발자를 위한 것입니다. 안드로이드, iOS, macOS, 윈도우, 리눅스 등 여러 플랫폼을 지원합니다.

사용 사례

  • 라이트 모드와 다크 모드 전환 구현
  • 사용자 테마 선호 설정 유지
  • 동적 테마를 사용하여 반응형 UI 만들기
  • 접근성 있는 앱 인터페이스 만들기
  • 사용자 맞춤형 외관 설정 활성화

주요 기능

  • 공유된 선호 사항을 통한 자동 테마 지속성
  • 테마 상태 관리를 위한 간단한 API
  • 크로스 플랫폼 호환성
  • 라이트 모드와 다크 모드 모두 지원
  • 기존 Flutter 프로젝트와의 간편한 통합

적합한 대상

  • 테마 사용자 정의 기능을 갖춘 앱을 개발하는 개발자
  • 지속적인 사용자 선호 설정이 필요한 앱
  • 다중 플랫폼을 대상으로 하는 프로젝트
  • 사용자 인터페이스 중심 애플리케이션
  • 테마 설정을 최소화하고 싶은 팀

고려 사항

  • shared_preferences 종속성 필요
  • 라이트/다크 모드만 가능
  • 복잡한 테마 변형을 위해 추가 로직이 필요할 수 있습니다
  • 고급 테마 시스템에 적합하지 않습니다
  • 앱 시작 시 올바른 초기화에 의존

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Theme Mode Builder 🚀

Pub Version GitHub GitHub Issues GitHub Pull Requests

I created this package to help standardize my apps way of theme handling.

Web Demo: https://theme-mode-builder.netlify.app/

Features:
  • 🚀 Cross platform: mobile, desktop, browser
  • ❤ Simple, powerful, intuitive API
  • 🛡 Null Safety
  • 🔋 Batteries included

📚 How to Use

Table of contents
  1. Video
  2. Guide
Video: (A bit outdated, for v0.0.3)

Guide:

First run the initialization which is asynchronous so you will need to change the return type of your main() method from void to Future<void>:

Future<void> main() async {
  /// ensure widgets are initialized
  WidgetsFlutterBinding.ensureInitialized();

  /// initialize theme mode builder
  await ThemeModeBuilderConfig.ensureInitialized();

  /// Runs the app :)
  runApp(MyCoolApp());
}

Then just wrap your MaterialApp widget with the ThemeModeBuilder and return the MaterialApp widget from the builder. The builder gives you two arguments, builder: (BuildContext context, ThemeMode themeMode) {}. Pass the themeMode to themeMode on your MaterialApp.

Now this code below explains better than I do 🙈🚀😂:

import "package:flutter/material.dart";
import "package:theme_mode_builder/theme_mode_builder.dart";

class MyCoolApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ThemeModeBuilder(
      builder: (BuildContext context, ThemeMode themeMode) {
        return MaterialApp(
          title: "My Cool App",

          /// here is the `themeMode` passed form the `builder`
          themeMode: themeMode,
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(
              brightness: Brightness.light,
              seedColor: Colors.red,
            ),

            /// put your light theme data here
          ),
          darkTheme: ThemeData(
            colorScheme: ColorScheme.fromSeed(
              brightness: Brightness.dark,
              seedColor: Colors.deepPurple,
            ),

            /// put your dark theme data here
          ),
          home: Home(),
        );
      },
    );
  }
}
If you want to change the themeMode you just call:
await ThemeModeBuilderConfig.toggleTheme();

And the theme will change instantly given you followed the steps above correctly 🎉.

Want more customization?

To change to dark mode:

await ThemeModeBuilderConfig.setDark();

To change to light mode:

await ThemeModeBuilderConfig.setLight();

To change to system mode:

await ThemeModeBuilderConfig.setSystem();
To get the theme mode you can run:
final ThemeMode themeMode = ThemeModeBuilderConfig.getThemeMode();
Finally, To check if the current theme is dark or not, you use this simple call:
final bool isDarkTheme = ThemeModeBuilderConfig.isDarkTheme();

카테고리

의존성

의존성 목록 4 개

소스 저장소

이 패키지를 사용하는 프로젝트