FLUTTER ECOSYSTEM

Norbert515/dynamic_theme

輕鬆動態變更您的主題

dynamic_theme 專案封面
Stars
319
Forks
60
最近推送(UTC)
2021年12月20日
專案狀態
未封存
Norbert Kozsir GitHub avatar
GITHUB User

Norbert Kozsir ↗

Mostly Flutter these days. Love to explore new technologies though.

FlutterFlowKarlsruhe, Germany官方網站 ↗
語言DartRubyObjective-CJava

此儲存庫發佈的套件

使用的依賴

依賴清單 3 項

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

展開 / 收合專案 README

dynamic_theme

Dynamically changing your theme without hassle

https://github.com/Norbert515/dynamic_theme/blob/master/assets/theme.png

This packages manages changing your theme during runtime and persiting that theme.

I wrote a medium post about this, check it out here!

Include in your project

dependencies:
  dynamic_theme: ^1.0.1

run packages get and import it

import 'package:dynamic_theme/dynamic_theme.dart';

if you want the dialog:

import 'package:dynamic_theme/theme_switcher_widgets.dart';

Usage

Wrap your material app like this:


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new DynamicTheme(
      defaultBrightness: Brightness.light,
      data: (brightness) => new ThemeData(
        primarySwatch: Colors.indigo,
        brightness: brightness,
      ),
      themedWidgetBuilder: (context, theme) {
        return new MaterialApp(
          title: 'Flutter Demo',
          theme: theme,
          home: new MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    );
  }
}

Change the theme like this:

  void changeBrightness() {
    DynamicTheme.of(context).setBrightness(Theme.of(context).brightness == Brightness.dark? Brightness.light: Brightness.dark);
  }
  
  void changeColor() {
    DynamicTheme.of(context).setThemeData(new ThemeData(
        primaryColor: Theme.of(context).primaryColor == Colors.indigo? Colors.red: Colors.indigo
    ));
  }

When changing the brightness with setBrightness, it is additionally stored in the shared preferences.

Also included

A dialog widget to change the brightness!

https://github.com/Norbert515/dynamic_theme/blob/master/assets/dialogs.png

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.