Questions tagged [dart]

Dart is a class-based, statically(& strongly)-typed programming language for building web and mobile applications. Dart compiles to modern JavaScript to run in the browser and compiles to native code to run on mobile platforms like Android and iOS. Dart also runs on the command-line for scripting and server-side apps.

Dart is an open-source, class-based, statically(& strongly)-typed (with inference) programming language for building web and mobile applications created by Google. Although Dart is statically-typed it supports dynamic-typing through the 'dynamic' type.

Dart’s design goals are:

  • Create a structured yet flexible language.
  • Make Dart feel familiar and natural to programmers and thus easy to learn.
  • Ensure that Dart delivers high performance on modern web browsers, mobile, and environments ranging from small handheld devices to server-side execution.

Dart targets a wide range of development scenarios, from a one-person project without much structure to a large-scale project needing formal types in the code to state programmer intent.

To support this wide range of projects, Dart provides the following features and tools:

  • Sound type system: A type system which feels lightweight thanks to inference and gives good safety
  • Mobile and Web frameworks: Dart developers can use Flutter on mobile and AngularDart on the web
  • IDE Integration: official plugins for Jetbrains' IDEs (IntelliJ IDEA / WebStorm etc) and Visual Studio Code. Community plugins also exist for many other editors backed by the Dart Analysis Server

Links

Documentation

FAQ

Chat Room

90488 questions
362
votes
19 answers

How do I supply an initial value to a text field?

I'd like to supply an initial value to a text field and redraw it with an empty value to clear the text. What's the best approach to do that with Flutter's APIs?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
356
votes
32 answers

How to use conditional statement within child attribute of a Flutter Widget (Center Widget)

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…
Marko
  • 4,857
  • 5
  • 17
  • 21
355
votes
24 answers

How do I format a date with Dart?

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".
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
354
votes
16 answers

Scaffold.of() called with a context that does not contain a Scaffold

As you can see, my button is inside the Scaffold's body. But I get this exception: Scaffold.of() called with a context that does not contain a Scaffold. import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends…
Figen Güngör
  • 12,169
  • 14
  • 66
  • 108
342
votes
8 answers

Passing data to StatefulWidget and accessing it in its state in Flutter

I have 2 screens in my Flutter app: a list of records and a screen for creating and editing records. If I pass an object to the second screen that means I am going to edit this and if I pass null it means that I am creating a new item. The editing…
moonvader
  • 19,761
  • 18
  • 67
  • 116
342
votes
17 answers

Sizing elements to percentage of screen width/height

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…
Luke
  • 6,388
  • 3
  • 26
  • 35
331
votes
24 answers

Flutter: how to prevent device orientation changes and force portrait?

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, …
boeledi
  • 6,837
  • 10
  • 32
  • 42
328
votes
12 answers

flutter doctor --android-licenses gives a java error

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156) at…
Vivek Kogilathota
  • 3,301
  • 2
  • 6
  • 3
325
votes
27 answers

Vertical viewport was given unbounded height

This is my code: @override Widget build(BuildContext context) { return new Material( color: Colors.deepPurpleAccent, child: new Column( mainAxisAlignment: MainAxisAlignment.center, children:[new…
pallav bohara
  • 6,199
  • 6
  • 24
  • 45
323
votes
16 answers

Yellow lines under Text Widgets in Flutter?

The main app screen doesn't have this issue, all the texts show up as they should. However, in the new screen, all the text widget have some weird yellow line / double-line underneath. Any ideas on why this is happening?
dasfima
  • 4,841
  • 3
  • 21
  • 24
321
votes
17 answers

How do I disable a Button in Flutter?

I'm just starting to get the hang of Flutter, but I'm having trouble figuring out how to set the enabled state of a button. From the docs, it says to set onPressed to null to disable a button, and give it a value to enable it. This is fine if the…
chris84948
  • 3,940
  • 3
  • 22
  • 25
318
votes
15 answers

Flutter: Run method on Widget build complete

I would like to be able to run functions once a Widget has finished building/loading but I am unsure how. My current use case is to check if a user is authenticated and if not, redirect to a login view. I do not want to check before and push either…
KingLagalot
  • 3,224
  • 2
  • 10
  • 11
317
votes
5 answers

List use of double dot (.) in dart?

Sometimes I see this List list = []; Then list..add(color) What's the difference between using 1 dot(.) and 2 dot(..)?
Daniel Mana
  • 9,451
  • 13
  • 29
  • 41
317
votes
19 answers

How do I generate random numbers in Dart?

How do I generate random numbers using Dart?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
316
votes
6 answers

What is the difference between functions and classes to create reusable widgets?

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, …
Rémi Rousselet
  • 256,336
  • 79
  • 519
  • 432