Buscar pacotes, repositórios e categorias de apps

Capa de dynamic_themes
Detalhes do pacotev1.1.0

dynamic_themes

Permite especificar um número de temas de cores para o usuário escolher. Persiste o tema selecionado entre reinicializações do aplicativo.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
2,7 mil
Curtidas
43
Pontos Pub
150

Instalar pacote

flutter pub add dynamic_themes

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Dynamic Themes é um pacote do Flutter que permite aos desenvolvedores implementar temas de cor personalizáveis, permitindo que os usuários escolham e alternem entre vários temas pré-definidos. Ele persiste automaticamente o tema selecionado pelo usuário após reinicializações do aplicativo, garantindo uma experiência consistente. O pacote suporta todas as principais plataformas, incluindo Android, iOS, Web, macOS, Windows e Linux, tornando-o ideal para aplicações multiplataforma que exigem capacidades de tematização dinâmica.

Casos de uso

  • Aplicativo com modos claro e escuro selecionáveis pelo usuário
  • Suporte a múltiplos temas em um único aplicativo
  • Preferências de tema persistentes após reinício do aplicativo
  • Consistência de tema multiplataforma
  • Esquemas de cores personalizados
  • retenção de preferência do usuário

Principais recursos

  • Configuração fácil de tema
  • Persistência automática do tema
  • Suporte para todas as plataformas do Flutter
  • API simples para alternância de tema
  • Predefinições de modo claro/escuro embutidas
  • Sistema de temas extensível

Indicado para

  • Desenvolvedores criando aplicativos com temas de interface personalizáveis
  • Aplicativos direcionados para múltiplas plataformas
  • Projetos que exigem preferências de usuário persistentes
  • Sistemas de design com paletas de cores da marca
  • Aplicações focadas na experiência do usuário e acessibilidade

Considerações

  • Requer configuração manual das cores do tema
  • Limitado a conjuntos de temas pré-definidos
  • Nenhuma geração de tema em tempo de execução
  • A troca de tema pode exigir reconstruções
  • Depende de preferências compartilhadas para persistência
  • Não otimizado para coleções muito grandes de temas

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

dynamic_themes

"Buy Me A Coffee"

Dynamically change between multiple themes

This package allows you to specify multiple themes for the user to choose from. The theme can be updated dynamically during runtime. The package persits the selected theme across app restarts.

image

Getting Started

Follow the instructions here.

Usage

This package allows for an arbitrary number of themes to be defined. Each theme has a unique ID of type int. To create the themes and map them to IDs, first you have to create an instance of ThemeCollection, e. g.:

final themeCollection = ThemeCollection(
    themes: {
        0: ThemeData(primarySwatch: Colors.blue),
        1: ThemeData(primarySwatch: Colors.red),
        2: ThemeData.dark(),
    },
    fallbackTheme: ThemeData.light(), // optional fallback theme, default value is ThemeData.light()
);

However, I would recommend to introduce a class with static const int values to associate a name to each ID value:


class AppThemes {
    static const int LightBlue = 0;
    static const int LightRed = 1;
    static const int Dark = 2;
}
final themeCollection = ThemeCollection(
    themes: {
        AppThemes.LightBlue: ThemeData(primarySwatch: Colors.blue),
        AppThemes.LightRed: ThemeData(primarySwatch: Colors.red),
        AppThemes.Dark: ThemeData.dark(),
    },
    fallbackTheme: ThemeData.light(),
);

Now, wrap your material app like this:

return DynamicTheme(
    themeCollection: themeCollection,
    defaultThemeId: AppThemes.LightBlue, // optional, default id is 0
    builder: (context, theme) {
        return MaterialApp(
            title: 'dynamic_themes example',
            theme: theme,
            home: HomePage(title: 'dynamic_themes example app'),
        );
    }
);

The theme can be set anywhere in the app, provided you have a BuildContext, e. g.:

DynamicTheme.of(context).setTheme(AppThemes.LightRed);

By setting the theme, its ID is automatically saved via the shared_preferences package, so the next time the app starts, the theme can be restored automatically.

Provided you have wrapped the MaterialApp in the DynamicTheme widget, you can access the current theme like you are used to it by calling

final theme = Theme.of(context);

If for any reason you can't access the theme this way, you can also call

final theme = DynamicTheme.of(context).theme;

To get the ID of the current theme, for example to create a selection UI as done in the example app provided with this package, call

final themeId = DynamicTheme.of(context).themeId;

Example

The example app can be found in the example folder. It implements a dropdown menu to select between 4 themes. The app is the source for the screenshots above.

Maintainer

If you experience any problems using this package, please create an issue on Github. Pull requests are also very welcome.

Many thanks to the dynamic_theme package from Norbert Kozsir this package was inspired by!

Categorias

Dependências

Lista de dependências 1 itens

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.