How do you detect the host platform from Dart code?

import ‘dart:io’ show Platform; if (Platform.isAndroid) { // Android-specific code } else if (Platform.isIOS) { // iOS-specific code } All options include: Platform.isAndroid Platform.isFuchsia Platform.isIOS Platform.isLinux Platform.isMacOS Platform.isWindows You can also detect if you are running on the web using kIsWeb, a global constant indicating if the application was compiled to run on the web: … Read more

How can I dismiss the on screen keyboard?

For Flutter version 2 or latest : Since Flutter 2 with null safety this is the best way: FocusManager.instance.primaryFocus?.unfocus(); Note: using old ways leads to some problems like keep rebuild states; For Flutter version < 2 : As of Flutter v1.7.8+hotfix.2, the way to go is: FocusScope.of(context).unfocus(); Comment on PR about that: Now that #31909 … Read more

How to change package name in flutter?

For Android App Name Change the label name in your AndroidManifest.xml file: <application android:name=”io.flutter.app.FlutterApplication” android:label=”TheNameOfYourApp” For Package Name Change the package name in your AndroidManifest.xml (in 3 of them, folders: main, debug and profile, according what environment you want to deploy) file: <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”your.package.name”> Also in your build.gradle file inside app folder defaultConfig { … Read more

How to change the application launcher icon on Flutter?

Flutter Launcher Icons has been designed to help quickly generate launcher icons for both Android and iOS: https://pub.dartlang.org/packages/flutter_launcher_icons Add the package to your pubspec.yaml file (within your Flutter project) to use it Within pubspec.yaml file specify the path of the icon you wish to use for the app and then choose whether you want to … Read more

Create a rounded button / button with border-radius in Flutter

1. Solution Summary FlatButton and RaisedButton are deprecated. So, you can use shape which placed in the style property, for TextButton and ElevatedButton. There are some changes since Flutter 2.0: style: the property type has changed to ButtonStyle shape: the property type has changed to MaterialStateProperty<T> 2. Rounded Button Inside the style property exists the … Read more