Flutter SDK offers two sets of styling widgets, the Material, and Cupertino Widget. The Material widget implements material design language for iOS, Android, web, and desktop applications. The Cupertino widget on the other hand is used to implement the current iOS design language based on Apple’s human interface guidelines.
So, here arises a question, why do we need a Cupertino widget for iOS app development when there is a Material widget that can be used for any platform including iOS.
Continue reading this article to know more about the Flutter Cupertino widget, why we need it, and how it helps you to build a beautiful cross-platform Flutter app that looks and feels like a native application.
The widget is specifically designed for the apps that run on the iOS platform. As the widget respects Android and iOS platform differences, it doesn’t support all the features in the Material widgets. Also, there are some licensing issues.
For example, if you run the Cupertino app on the Android platform you might not see the correct fonts loaded on the UI belonging to the San Francisco font family. Also, you may experience the pages getting dismissible via a back swipe.
Here are some basic things you need to know before using the Cupertino widget in the Flutter app.
Google introduced Material Design to work with any platform and not just Android. So, when you develop an app in Flutter with the Material widget, it doesn’t mean it will automatically get designed into the respective platforms.
It's a developer's responsibility to check the platform and design its components according to the platform standards. You can check whether the platform is Android or iOS using different conditions, such as:
1 if(Platform.isIOS){ 2 return CupertinoButton(); 3 } 4 else if(Platform.IsAndroid){ 5 return ElevatedButton(); 6 } 7
However there is another sophisticated way i.e flutter_platform widgets, it simplifies the use of both Material and Cupertino widgets with a single widget.
First, install the plugin with flutter pub add flutter_platform_widgets . Then you need to create a base application using the PlatformProvider and PltformApp .
Then you can extend the app and utilize different platform widgets for building cross-platform apps with a simplified codebase.
1 import 'package:flutter/widgets.dart'; 2 import 'package:flutter_adapt_style_platform/selector_screen.dart'; 3 import 'package:flutter_adapt_style_platform/styles.dart'; 4 import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; 5 6 class App extends StatelessWidget { 7 @override 8 Widget build(BuildContext context) { 9 return PlatformProvider( 10 builder: (BuildContext context) => PlatformApp( 11 title: 'Flutter platform style sample', 12 material: (_, __) => MaterialAppData( 13 theme: materialTheme, debugShowCheckedModeBanner: false), 14 cupertino: (_, __) => CupertinoAppData( 15 theme: cupertinoTheme, debugShowCheckedModeBanner: false), 16 home: SelectorScreen())); 17 } 18 } 19
In the sample code you can clearly see how we can render the material widget in the material context and the Cupertino widget in the Cupertino context using the PlatformProvider and the PlatformApp.
There are many other widgets under the Flutter Platform Widgets that help you to build a cross-platform app for Android and iOS that looks more native to the platforms.
So, now you know how you can achieve personalized results in the cross-platform application using the material and Cupertino widget.
DhiWise is the app development platform for web and mobile apps that aims to accelerate the process of software development by eliminating the grunt tasks. The platform provides the best features necessary to make the development process more efficient and error-free.
So, if you want to build a cross-platform application with Flutter try using DhiWise Flutter Builder.
Here are its best features:
Also, read our article on Why to choose DhiWise for Flutter application development.
Well, besides all these it provides support for other Frontend and backend technologies, enabling full-stack application development using the single platform.
Tired of manually designing screens, coding on weekends, and technical debt? Let DhiWise handle it for you!
You can build an e-commerce store, healthcare app, portfolio, blogging website, social media or admin panel right away. Use our library of 40+ pre-built free templates to create your first application using DhiWise.