In Google's mobile framework Flutter, you can build your app using either Cupterino (iOS) widgets or Material Design (Android) widgets. This means you have to build your app twice in order to create two different styles consistent to each device -- one time using Cupertino widgets to build for iOS, and then another time using Material Design widgets to build for Android. Is there a way to auto-theme these widgets to tailor to each platform so I can avoid building a Flutter app twice?
Yes, of course this is possible. You can use the inherited Theme widget to get the ThemeData object of your MaterialApp.
ThemeData has a property called platform, which can be used to supply different widgets for different platforms. In your Android-iOS case, it would look something like this:
#override
Widget build(BuildContext contect) =>
Theme.of(context).platform == TargetPlatform.iOS ? // ternary if statement to check for iOS
CupertinoAlertDialog() : // Cupertino style dialog
AlertDialog(); // Material style dialog
As you can see, you can use a TargetPlatform constant to check on what platform your application is running.
This can obviously also be applied to icons etc.
If you are using the Flutter plugin for Android Studio or IntelliJ IDEA, you can also use the Flutter Inspector to switch the TargetPlatform on the fly, i.e. emulate that the Flutter SDK is running on iOS even though you are on Android and vise versa.
Related
I got a requirement to use the natively developed screen as a form of widget in the flutter code.
say i have a screen where half of the screen contains google-map for some height and rest of the design includes some other widgets. Here i want the google-map widget-a natively developed screen in the flutter as a widget(not as a screen directly but as a form of widget).
I want to know whether it is possible to do this way or not if yes how can we achieve this if anyone have any resources or links please share , it would be helpful to me.
Thanks in advance.
I am attempting to internationalize a flutter application using the Android Studio/VS Code Flutter Intl plugin. I can get the S.of(context).value to work throughout the app in widgets I've made myself and basic Text widgets but when I use it in Flutter widgets (Text Form field, list tile, drop down menu item, dropdown button, etc) I get the "NoSuchMethodError: the getter 'value' was called on null. It seems like there might be an issue between the static pieces of the Flutter widgets and the dynamic nature of the internationalized text?
Is there a way to correct this without making all of my own widgets?
As far as I know Flutter have build in widget system that named material and cupertino. But is there any other widgets sets. I want to build site with Flutter but do not want to make it look as mobile app.
No there isn't any other widget set. Flutters material and cupertino are ment to get your app a native look. They don't have any special functionality than visual design.
If you just want to do your own styling and elements, you can build your widgets by your own. You can read more about it here:
https://www.raywenderlich.com/10126984-creating-reusable-custom-widgets-in-flutter
I have to build a flutter app where the data need to be shown on home screen
of the phone, if the app is in background mode.
Till now i have not found any relevant information regarding the home screen widget or how to create the app widget in flutter except the one that
we can build app widget in native(Android/iOS).
Native widget in android
Do i need to handle app widget from the native code or is there a way to handle app widget in flutter.
It's not official supported, but there are some packages, to do the basic stuff:
https://pub.dev/packages/home_widget
Android
iOS
There is also a ticket in the Flutter repo: Explore home widgets for iOS 14. So you can upvote this ticket, if you are interested.
The firebase_admob plugin has support for banner ad which can be placed only on a fixed set of positions (top,bottom) because its just putting native view in top of the flutters activity/ViewController. Is it possible no to export BannerAd as a widget using PlatformView?
Or is it somehow possible right now to add banner ad inside a scrollable widget of flutter.
You can try thís https://pub.dartlang.org/packages/flutter_native_admob. It uses exact PlatformView as you expect. But the limitation is not supporting iOS yet.
Warning: The plugin is based on Flutter PlatformView (AndroidView) to
create a custom widget from Native View. Therefore, only Android is
supported at the moment. For iOS, wait for Flutter team to implement
iOSView equivalent.