adaptive_theme 3.3.0
adaptive_theme: ^3.3.0 copied to clipboard
Allows to change between light and dark theme dynamically and add system adaptive theme support.
example/lib/main.dart
// Copyright © 2020 Birju Vachhani. All rights reserved.
// Use of this source code is governed by an Apache license that can be
// found in the LICENSE file.
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:example/cupertino_example.dart';
import 'package:example/material_example.dart';
import 'package:flutter/cupertino.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 StatefulWidget {
final AdaptiveThemeMode? savedThemeMode;
const MyApp({super.key, this.savedThemeMode});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool isMaterial = true;
@override
Widget build(BuildContext context) {
return AnimatedSwitcher(
duration: const Duration(seconds: 1),
child: isMaterial
? MaterialExample(
savedThemeMode: widget.savedThemeMode,
onChanged: () => setState(() => isMaterial = false))
: CupertinoExample(
savedThemeMode: widget.savedThemeMode,
onChanged: () => setState(() => isMaterial = true)),
);
}
}