How do I generate random numbers in Dart?
How do I generate random numbers using Dart? 19 Answers 19
How do I generate random numbers using Dart? 19 Answers 19
I’m getting a rendering exception that I don’t understand how to fix. I’m attempting to create a column that has 3 rows. Row [Image] Row [TextField ] Row [Buttons] Here is my code to build the container: Container buildEnterAppContainer(BuildContext context) { var container = new Container( padding: const EdgeInsets.all(8.0), child: new Column( mainAxisAlignment: MainAxisAlignment.start, children: … Read more
I have realized that it is possible to create widgets using plain functions instead of subclassing StatelessWidget. An example would be this: Widget function({ String title, VoidCallback callback }) { return GestureDetector( onTap: callback, child: // some widget ); } This is interesting because it requires far less code than a full-blown class. Example: class … Read more
So far whenever I needed to use a conditional statement within a Widget I have done the following (Using Center and Containers as simplified dummy examples): new Center( child: condition == true ? new Container() : new Container() ) Though when I tried using an if/else statement it would lead to an Dead code warning: … Read more
For various reasons, sometimes the build method of my widgets is called again. I know that it happens because a parent updated. But this causes undesired effects. A typical situation where it causes problems is when using FutureBuilder this way: @override Widget build(BuildContext context) { return FutureBuilder( future: httpCall(), builder: (context, snapshot) { // create … Read more
Can I create something similar to Toasts in Flutter? Just a tiny notification window that is not directly in the face of the user and does not lock or fade the view behind it. 31 Answers 31 UPDATE: Scaffold.of(context).showSnackBar is deprecated in Flutter 2.0.0 (stable) You can access the parent ScaffoldMessengerState using ScaffoldMessenger.of(context). Then do … Read more
Sometimes I see this List list = []; Then list..add(color) What’s the difference between using 1 dot(.) and 2 dot(..)? 5 Answers 5
I would like to prevent my application from changing its orientation and force the layout to stick to “portrait”. In the main.dart, I put: void main(){ SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown ]); runApp(new MyApp()); } but when I use the Android Simulator rotate buttons, the layout “follows” the new device orientation… How could I solve this? Thanks … Read more
Is there a simple (non-LayoutBuilder) way to size an element relative to screen size (width/height)? For example: how do I set the width of a CardView to be 65% of the screen width. It can’t be done inside the build method (obviously) so it would have to be deferred until post build. Is there a … Read more
I have an instance of DateTime and I would like to format that to a String. How do I do that? I want to turn the date into a string, something like “2013-04-20”. 23 Answers 23