flutter_platform_widgets 7.0.1 flutter_platform_widgets: ^7.0.1 copied to clipboard
Simplifying the use of both Material and Cupertino widgets with a single widget
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'platform_page.dart.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ThemeMode? themeMode = ThemeMode.light; // initial brightness
@override
Widget build(BuildContext context) {
final materialLightTheme = ThemeData.light();
final materialDarkTheme = ThemeData.dark();
const darkDefaultCupertinoTheme =
CupertinoThemeData(brightness: Brightness.dark);
final cupertinoDarkTheme = MaterialBasedCupertinoThemeData(
materialTheme: materialDarkTheme.copyWith(
cupertinoOverrideTheme: CupertinoThemeData(
brightness: Brightness.dark,
barBackgroundColor: darkDefaultCupertinoTheme.barBackgroundColor,
textTheme: CupertinoTextThemeData(
primaryColor: Colors.white,
navActionTextStyle:
darkDefaultCupertinoTheme.textTheme.navActionTextStyle.copyWith(
color: const Color(0xF0F9F9F9),
),
navLargeTitleTextStyle: darkDefaultCupertinoTheme
.textTheme.navLargeTitleTextStyle
.copyWith(color: const Color(0xF0F9F9F9)),
),
),
),
);
final cupertinoLightTheme =
MaterialBasedCupertinoThemeData(materialTheme: materialLightTheme);
return PlatformProvider(
settings: PlatformSettingsData(
iosUsesMaterialWidgets: true,
iosUseZeroPaddingForAppbarPlatformIcon: true,
),
builder: (context) => PlatformTheme(
themeMode: themeMode,
materialLightTheme: materialLightTheme,
materialDarkTheme: materialDarkTheme,
cupertinoLightTheme: cupertinoLightTheme,
cupertinoDarkTheme: cupertinoDarkTheme,
matchCupertinoSystemChromeBrightness: true,
onThemeModeChanged: (themeMode) {
this.themeMode = themeMode; /* you can save to storage */
},
builder: (context) => PlatformApp(
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
title: 'Flutter Platform Widgets',
home: PlatformPage(),
),
),
// ),
);
}
}