This is Flutter design system & responsive tutorial package.
- Install
flutter_design_system
package.
flutter pub add flutter_design_system
- Wrap the root widget with
ThemeInjector
.
import 'package:flutter_design_system/flutter_design_system.dart';
void main() {
runApp(
const ThemeInjector(
child: MyApp(),
),
);
}
- Pass
context.themeService.themeData
andnavigatorKey
toMaterialApp
, and callToast.init()
inbuilder
.
final GlobalKey<NavigatorState> navigatorKey = GlobalKey();
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: navigatorKey,
theme: context.themeService.themeData,
builder: (context, child) => Toast.init(navigatorKey, child),
...
);
}
You can also create custom light and dark theme by implements AppTheme
.
class MyLightTheme implements AppTheme {}
class MyDarkTheme implements AppTheme {}
Inject your custom themes as below.
void main() {
runApp(
ThemeInjector(
themeService: ThemeService(
brightness: Brightness.dark, // Current theme
lightTheme: MyLightTheme(), // My light theme
darkTheme: MyDarkTheme(), // My dark theme
),
child: const MyApp(),
),
);
}
Light Theme | Dark Theme |
---|---|
SizedBox(
width: context.layout(
100, // base(mobile)
tablet: 200, // tablet
desktop: 300, // desktop
),
);