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

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

How to customize a date picker

Flutter 2.0.2 showDatePicker( builder: (context, child) { return Theme( data: Theme.of(context).copyWith( colorScheme: ColorScheme.light( primary: Colors.yellow, // header background color onPrimary: Colors.black, // header text color onSurface: Colors.green, // body text color ), textButtonTheme: TextButtonThemeData( style: TextButton.styleFrom( foregroundColor: Colors.red, // button text color ), ), ), child: child!, ); }, ); }, );