Material Datepicker with Cupertino UI - flutter

I have Flutter app that is using Cupertino UI components. I want to show the the Material design date_picker instead of IOS style date picker. Is there any way I can do this?
In short I want to keep the same Material style date picker for both Android and IOS app. But whenever I use the date picker under Cupertino it throws an exception "The specific widget that could not find a Material ancestor".
Thank you for your time

According to this medium post you can create an abstract class extending a StatelessWidget and using the dart.io package to determine the platform type. In your case you can test whether the underlying platform is IOS and use the material date picker using this :
if(Platform.isIOS) {
return createAndroidWidget(context);
}
you can find the full code in the aforementioned post and it'll be easy to follow it.

Related

How to use badge component from material design 3 in flutter 3.3.7

I recently find that flutter supports material design 3 by enabling the useMaterial3 in ThemeData. However, when I try to use the Badge component from material design 3, it could not be found, and I also cannot find too much information about the newly introduced components in material design 3. Can I please get some guidance on it? Is there any list of components from material design 3 can be used? Thank you.
You can start using Material 3 Badge widget in Flutter 3.7.
Ref: https://medium.com/flutter/whats-new-in-flutter-3-7-38cbea71133c

Flutter: Make text/images selectable in whole web app

In the Flutter web apps, there is no default functionality which makes text and images in the app selectable.
Is there a way to enable selection functionality for text/image on web?
I did check SelectableText widget but it is only for text and I would need to use it over every text. Also, you can't select text in multiple SelectableText widgets at once, you can only select text in one of them. I'm looking for a solution to select all text in the app without making change to every text widget.
Let me know if there’s one step solution to achieve this thing in whole web app.
In Flutter 3.3, with the introduction of the SelectableArea widget, any child of the SelectableArea widget has selection enabled for free!
To take advantage of this powerful new feature, simply wrap your route body (such as the Scaffold) with the SelectionArea widget and let Flutter do the rest.
For a more comprehensive deep dive into this awesome new feature, please visit the SelectableArea API page.
Flutter Web currently does not support multiple text selection across SelectableText widgets.
However, there are some experimental widgets that people are currently working on. According to a guide available at:
Custom SelectableScope Widget
They have proposed a custom widget, a Selectable scope, which basically allows for anything within it to be selectable (currently text and images)
NOTE: THIS IS CURRENTLY UNDER EXPERIMENTATION AND MIGHT CHANGE AS MENTIONED IN THE PROVIDED LINK.

Does Flutter have widgets other than material and cupertino?

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

How to create a dropdown for ios using flutter?

I can create a dropdown for android using DropdownButton and DropdownMenuItem widgets.But for ios I couldn't see any widgets like dropdown. I have seen on Cupertino (iOS-style) widgets also, but I didn't get any idea.Is there any option to create a dropdown for ios?
In iOS, the dropdown known as Picker. You can try the Cupertino Picker Widget.
Here is the Documentation: https://api.flutter.dev/flutter/cupertino/CupertinoPicker-class.html
And Here is the repo with an example, that will show you how you can implement: https://github.com/dhuma1981/Flutter_Cupertino_Demo

Is it possible to auto-theme widgets in Flutter?

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.