flutter_helper_utils 4.1.0 flutter_helper_utils: ^4.1.0 copied to clipboard
The Flutter Helper Utils Package offers various extensions and helper methods that can make development more efficient.
import 'package:flutter/material.dart';
import 'package:flutter_helper_utils/flutter_helper_utils.dart';
void main() {
runApp(const MyApp());
}
final themeModeNotifier = ThemeMode.light.notifier;
class MyApp extends StatelessWidget {
// Create a ValueNotifier for the theme mode.
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return themeModeNotifier.listenableBuilder(
(themeMode) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: themeMode,
// Use the value from the ValueNotifier
home: const MyHomePage(),
);
},
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
final theme = context.themeData;
return Scaffold(
appBar: AppBar(
title: const Text("Theme Mode Switcher"),
actions: [
Switch(
value: theme.isDark,
onChanged: (value) {
themeModeNotifier.value =
value ? ThemeMode.dark : ThemeMode.light;
},
),
],
),
body: Center(
child: Text(
"Theme Mode is: ${theme.brightness.name}",
style: theme.displayMedium,
),
),
);
}
}