themeProvider function
ThemeProvider
themeProvider({
- bool debugShowCheckedModeBanner = false,
- required BuildContext context,
- required Widget child,
Wrapper function to setup a default ThemeProvider from 'package:theme_provider/theme_provider.dart'
childshould not be wrapped inside MaterialApp, as the function is already doing itdebugShowCheckedModeBannerwill be passed on to MaterialApp inside
Example
import 'package:lazy/lazy.dart';
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return lazy.themeProvider(
debugShowCheckedModeBanner: false,
context: context,
child: Home(),
);
}
}
Implementation
ThemeProvider themeProvider({
bool debugShowCheckedModeBanner = false,
required BuildContext context,
required Widget child,
}) {
return ThemeProvider(
saveThemesOnChange: true,
loadThemeOnInit: false,
onInitCallback: _themeProviderOnInitialCallBack,
themes: <AppTheme>[
AppTheme.light(id: 'light'),
AppTheme.dark(id: 'dark'),
],
child: ThemeConsumer(
child: Builder(
builder: (context) => MaterialApp(
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
theme: ThemeProvider.themeOf(context).data,
home: child,
),
),
),
);
}