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

패키지 상세v3.0.0

theme_mode_handler

런타임 중에 `themeMode` 를 변경하고 재시작 간에 유지하기 위한 Flutter 위젯

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
215
좋아요
19
Pub 점수
160

패키지 설치

flutter pub add theme_mode_handler

패키지 개요

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

런타임 중 동적으로 테마 모드를 전환할 수 있고 앱 재시작 후에도 선택한 테마를 유지하는 플러터 패키지입니다. 사용자의 선택을 공유된 선호 설정에 자동으로 저장함으로써 밝은 모드와 어두운 모드의 설정을 간편하게 처리하고, 앱을 다시 열었을 때 일관성을 보장합니다. 최소한의 설정으로 기존 플러터 앱에 원활하게 통합되며, 수동 스토리지 로직 없이도 테마 상태를 신뢰할 수 있게 관리할 수 있습니다.

사용 사례

  • 모바일 앱에서의 동적 테마 전환
  • 세션 간에 사용자 테마 선호도 유지
  • 웹 애플리케이션에서 다크 모드 전환 구현
  • 시스템 테마 인식 지원
  • 데스크톱 앱에서 테마 사용자 정의 활성화

주요 기능

  • 런타임 테마 모드 변경
  • 공유 설정을 사용한 자동 지속성
  • MaterialApp과의 간단한 통합
  • 모든 주요 플랫폼을 지원합니다
  • 사용자 지정 가능한 기본 테마 모드

적합한 대상

  • 테마 전환 기능을 가진 앱을 개발하는 개발자
  • 지속적인 사용자 테마 설정이 필요한 앱
  • 다양한 장치를 대상으로 하는 크로스 플랫폼 애플리케이션

고려 사항

  • shared_preferences 종속성 필요
  • themeMode에만 제한됨(완전한 테마 사용자 정의는 아님)
  • 사용자 정의 테마를 위해 추가 로직이 필요할 수 있습니다
  • 모드 전환을 넘어서는 복잡한 테마 관리에는 적합하지 않습니다

원본 README

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

theme_mode_handler

This library is considered done - no new features or changes are foreseen. You may not see recent updates to this repository, but the library is totally functional. Please open an issue if you find an issue or think something is missing so we can discuss it.

version All Contributors

Flutter widget to change themeMode during runtime and persist it across restarts.

Motivation

Flutter 1.9 introduced a new way to control which theme is used: MaterialApp.themeMode. If you have specified the darkTheme and theme properties, you can use themeMode to control it. The property defaults to ThemeMode.system.

This package wraps this functionality and allows you to persist and retrieve the user's preference wherever you want by implementing an interface.

Installation

Add this to your pubspec.yaml:

dependencies:
  theme_mode_handler: ^3.0.0

Usage

  • Create a class that implements the IThemeModeManager interface:
class MyManager implements IThemeModeManager {
  @override
  Future<String> loadThemeMode() async {}

  @override
  Future<bool> saveThemeMode(String value) async {}
}
  • Import the ThemeModeHandler widget, wrap MaterialApp with it and pass it an instance of your manager:
import 'package:theme_mode_handler/theme_mode_handler.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ThemeModeHandler(
      manager: MyManager(),
      builder: (ThemeMode themeMode) {
        return MaterialApp(
          themeMode: themeMode,
          darkTheme: ThemeData(
            brightness: Brightness.dark,
          ),
          theme: ThemeData(
            brightness: Brightness.light,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      },
    );
  }
}
  • Change the themeMode with:
ThemeModeHandler.of(context).saveThemeMode(value);
  • Get the current themeMode with:
ThemeModeHandler.of(context).themeMode;

Check the example folder for a complete example.

API

builder

Type: Widget Function(ThemeMode themeMode).

Function that runs when themeMode changes.

manager

Type: IThemeModeManager.

Implementation of IThemeModeManager to load and save the selected value.

defaultTheme

Type: ThemeMode.

Default value to be used when manager.loadThemeMode returns null or an invalid value.

placeholderWidget

Type: Widget?.

While the themeMode is loaded, you can choose to render a different widget. By default, it'll render an empty container.

Extra

This package exports a dialog and a method to simplify its usage.

  • Import the dialog with:
import 'package:theme_mode_handler/theme_picker_dialog.dart';
  • Use it like this:
void _selectThemeMode(BuildContext context) async {
  final newThemeMode = await showThemePickerDialog(context: context);
  print(newThemeMode);
}

Inspiration

This package is inspired and based on the great package dynamic_theme.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Arthur Denner

💻 🎨 💡 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Arthur Denner

카테고리

소스 저장소

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