Flutter Detect Device Platform is Android or iOS & Load Different Widget Example Tutorial

Flutter has a inbuilt class named as Platform which is used to get information about the current running environment on which the application is running like Android platform or iOS platform. There are two inbuilt method define in this class one is Platform.isAndroid used to detect platform operating system is Android. Second is Platform.isIOS used to detect platform operating system is iOS. The both platform method returns value in Boolean True False form. If they detect the OS then they return us in True. So in this tutorial we would Flutter Detect Device Platform is Android or iOS & Load Different Widget Example Tutorial.

Contents in this project Flutter Detect Device Platform is Android or iOS & Load Different Widget Example Tutorial:

1. Import material.dart package and Platform package in your app’s main.dart file.

2. Call our main MyApp class using void main runApp() method.

3. Create our main class MyApp extends with State less widget.

4. Create a Widget build function named as _detectWidget(). We have to use the Widget keyword to make a drawable widget using function. In this function we would detecting device OS version and according to that show the widget on screen.

5. Creating Widget build area in MyApp class and call our _detectWidget().

6. Complete source code for main.dart file:

Screenshot in Android device:

Screenshot in iOS device:

Flutter Detect Device Platform is Android or iOS & Load Different Widget Example Tutorial

Leave a Reply

Your email address will not be published.