flutter_extended_platform_widgets 1.0.2 flutter_extended_platform_widgets: ^1.0.2 copied to clipboard
Simplifying the use of both Material, Cupertino, Fluent, MacOS, Linux, and Fuchsia widgets with a single widget
import 'package:fluent_ui/l10n/generated/fluent_localizations.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_extended_platform_widgets/flutter_extended_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,
...FluentLocalizations.localizationsDelegates,
],
title: 'Flutter Platform Widgets',
home: PlatformPage(),
),
),
// ),
);
}
}