How can I detect if my Flutter app is running in the web?

There is a global boolean kIsWeb which can tell you whether or not the app was compiled to run on the web. Documentation: https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html import ‘package:flutter/foundation.dart’ show kIsWeb; if (kIsWeb) { // running on the web! } else { // NOT running on the web! You can check for additional platforms here. }

How to set Custom height for Widget in GridView in Flutter?

The key is the childAspectRatio. This value is use to determine the layout in GridView. In order to get the desired aspect you have to set it to the (itemWidth / itemHeight). The solution would be this: class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => … Read more

Difference between List.from() and as List in Dart

Let’s examine some examples: var intList = <int>[1, 2, 3]; var dynamicList = intList as List<dynamic>; // Works. var intList2 = dynamicList as List<int>; // Works. But: var dynamicList = <dynamic>[1, 2, 3]; var intList = dynamicList as List<int>; // Fails at runtime. What’s the difference? In the first example, intList has a static type … Read more

Flutter – save file to download folder – downloads_path_provider

path_provider will probably undergo some changes soon, there are some open issues: https://github.com/flutter/flutter/issues/35783 As of right now, the best way to get the download path on an Android device is to use: /storage/emulated/0/Download/ No (s) needed. And to get the external dir path in Android: /storage/emulated/0/ The “emulated” word does not mean it’s the emulator … Read more

Android Studio Emulator: cannot add library vulkan-1.dll: failed

I don’t know whether Microsoft Visual Studio Code (VS Code) itself needs vulkan-1.dll or any of my following Visual Studio Code extensions, as I found out that you may find the missing vulkan-1.dll at Visual Studio Code’s following folder path: C:\Users\{your_username}\AppData\Local\Programs\Microsoft VS Code\ So, if you have Microsoft Visual Studio Code installed, you may find … Read more

How to set state from another widget?

Avoid this whenever possible. It makes these widgets depends on each others and can make things harder to maintain in the long term. What you can do instead, is having both widgets share a common Listenable or something similar such as a Stream. Then widgets interact with each other by submitting events. For easier writing, … Read more