September 2019
Beginner
512 pages
12h 52m
English
When developing mobile apps for multiple platforms, we may need to make different designs for different targets. To do that, we can use the Platform class, which helps us get information about the environment, mainly the target operating system, through its getters:
With these getters, we can make our whole widget tree have specific implementations for each platform. Here's an example:
// part of theme/lib/main.dart exampleclass PlatformSpecificWidgets extends StatelessWidget { @override Widget build(BuildContext context) { return Platform.isAndroid ? MaterialApp( theme: ThemeData(primaryColor: Colors.grey), ) : CupertinoApp( theme: CupertinoThemeData(primaryColor: CupertinoColors.lightBackgroundGray), ...Read now
Unlock full access