Target the specific design of Material for Android and Cupertino for iOS widgets through a common set of Platform aware widgets
Setup of the application is completely optional. All the platform widgets work without this setup if you have a MaterialApp
as your app bootstrap widget.
However, to be closer to the actual iOS (cupertino)
platform styling and behavour it is adviseable to use PlatformApp
. If you need to add further configuration or need to switch between Cupertino and Material styles you need to add PlatformProvider
PlatformProvider(
builder: (context) => PlatformApp(
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
title: 'Flutter Platform Widgets',
home: MyHomePage(),
),
)
or if you want to use the new Navigator 2.0 use PlatformApp.router
PlatformProvider(
builder: (context) => PlatformApp.router(
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
title: 'Flutter Platform Widgets',
routeInformationParser: ...
routerDelegate: ...
),
)
NOTE: Adding
localizationsDelegates
is important forCupertino
since some widgets expect localization to be set up.
If you need to use Material
widgets within your Cupertino
app such as ListTile
you need to have the following setting.
PlatformProvider(
settings: PlatformSettingsData(iosUsesMaterialWidgets: true),
builder: ...
)
Without this you will get an exception stating that there is no Material widget as a parent for some of your Material
widgets.