adaptive_theme 1.1.0 copy "adaptive_theme: ^1.1.0" to clipboard
adaptive_theme: ^1.1.0 copied to clipboard

outdated

Allows to change between light and dark theme dynamically and add system adaptive theme support.

example/lib/main.dart

import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final savedThemeMode = await AdaptiveTheme.getThemeMode();
  runApp(MyApp(savedThemeMode: savedThemeMode));
}

class MyApp extends StatelessWidget {
  final AdaptiveThemeMode savedThemeMode;

  const MyApp({Key key, this.savedThemeMode}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AdaptiveTheme(
      light: ThemeData(
        brightness: Brightness.light,
        primarySwatch: Colors.red,
        accentColor: Colors.amber,
      ),
      dark: ThemeData(
        brightness: Brightness.dark,
        primarySwatch: Colors.red,
        accentColor: Colors.amber,
      ),
      initial: savedThemeMode ?? AdaptiveThemeMode.light,
      builder: (theme, darkTheme) => MaterialApp(
        title: 'Adaptive Theme Demo',
        theme: theme,
        darkTheme: darkTheme,
        home: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return AnimatedTheme(
      duration: Duration(milliseconds: 300),
      data: Theme.of(context),
      child: Scaffold(
        appBar: AppBar(
          title: Text('Adaptive Theme Demo'),
        ),
        body: SizedBox.expand(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              RaisedButton(
                onPressed: () {
                  AdaptiveTheme.of(context).toggleThemeMode();
                },
                child: Text('Toggle Theme Mode'),
              ),
              RaisedButton(
                onPressed: () {
                  AdaptiveTheme.of(context).setDark();
                },
                child: Text('Set Dark'),
              ),
              RaisedButton(
                onPressed: () {
                  AdaptiveTheme.of(context).setLight();
                },
                child: Text('set Light'),
              ),
              RaisedButton(
                onPressed: () {
                  AdaptiveTheme.of(context).setSystem();
                },
                child: Text('Set System Default'),
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {},
          child: Icon(Icons.add),
        ),
      ),
    );
  }
}
888
likes
40
points
40.3k
downloads

Publisher

verified publisherbirju.dev

Weekly Downloads

Allows to change between light and dark theme dynamically and add system adaptive theme support.

Repository (GitHub)
Contributing

License

Apache-2.0 (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on adaptive_theme