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
212
votes
15 answers

How can I get the height of a widget?

I don't understand how LayoutBuilder is used to get the height of a widget. I need to display the list of Widgets and get their height, so I can compute some special scroll effects. I am developing a package and other developers provide a widget (I…
JoKr
  • 4,976
  • 8
  • 27
  • 39
211
votes
5 answers

What's the difference between async and async* in Dart?

I am making an application using flutter framework . During this I came across with the keywords in Dart async and async*. Can anybody tell me what's the difference between them?
Jagraj Singh
  • 4,031
  • 4
  • 15
  • 33
210
votes
16 answers

Enumerate or map through a list with index and value in Dart

In dart there any equivalent to the common: enumerate(List) -> Iterator((index, value) => f) or List.enumerate() -> Iterator((index, value) => f) or List.map() -> Iterator((index, value) => f) It seems that this is the easiest way but it still…
David Rees
  • 6,792
  • 3
  • 31
  • 39
210
votes
11 answers

How do I add Methods or Values to Enums in Dart?

In Java when you are defining an enum, you can do something similar to the following, i.e. add members to an enum. Is this possible in Dart? enum Foo { one(1), two(2); final num value; Foo(this.value); }
Digital Deception
  • 2,677
  • 2
  • 15
  • 24
208
votes
11 answers

How to convert a double to an int in Dart?

The following produces the below error: int calc_ranks(ranks) { double multiplier = .5; return multiplier * ranks; } The return type double is not a int, as defined by the method calc_ranks. How do I round/cast to an int?
Todd Chambery
  • 3,195
  • 4
  • 19
  • 27
207
votes
11 answers

type 'List' is not a subtype of type 'List'

I have a snippet of code which I copied from Firestore example: Widget _buildBody(BuildContext context) { return new StreamBuilder( stream: _getEventStream(), builder: (context, snapshot) { if (!snapshot.hasData) return new…
Arash
  • 11,697
  • 14
  • 54
  • 81
207
votes
13 answers

How to Determine Screen Height and Width

I've created a new application on Flutter, and I've had problems with the screen sizes when switching between different devices. I created the application using the Pixel 2XL screen size, and because I've had containers with a child of ListView it's…
Tom O'Sullivan
  • 3,416
  • 5
  • 15
  • 27
206
votes
8 answers

How do I bold (or format) a piece of text within a paragraph?

How can I have a line of text with different formatting? e.g.: Hello World
Dvdwasibi
  • 10,537
  • 7
  • 22
  • 22
206
votes
32 answers

Dart How to get the name of an enum as a String

Before enums were available in Dart I wrote some cumbersome and hard to maintain code to simulate enums and now want to simplify it. I need to get the name of the enum as a string such as can be done with Java but cannot. For instance little test…
Nate Lockwood
  • 3,325
  • 6
  • 28
  • 34
204
votes
11 answers

Flutter position stack widget in center

I have widgets in a stack so I'd like to position my button bar in the bottom center of the stack but nothing works. The widget just sticks to the left side. here is my code. new Positioned( bottom: 40.0, child: new…
spongyboss
  • 8,016
  • 15
  • 48
  • 65
203
votes
32 answers

How to solve Flutter CERTIFICATE_VERIFY_FAILED error while performing a POST request?

I am sending a post request in Dart. It is giving a response when I test it on API testing tools such as Postman. But when I run the app. It gives me the following error:- E/flutter ( 6264): HandshakeException: Handshake error in client (OS Error:…
Adil Maqusood
  • 2,509
  • 3
  • 10
  • 13
203
votes
13 answers

How do I combine two lists in Dart?

I was wondering if there was an easy way to concatenate two lists in dart to create a brand new list object. I couldn't find anything and something like this: My list: list1 = [1, 2, 3] list2 = [4, 5, 6] I tried: var newList = list1 + list2; I…
Alex
  • 2,033
  • 2
  • 11
  • 7
201
votes
16 answers

Flutter: Setting the height of the AppBar

How can I simply set the height of the AppBar in Flutter? The title of the bar should be staying centered vertically (in that AppBar).
Buğra Ekuklu
  • 3,049
  • 2
  • 17
  • 28
196
votes
7 answers

List firstWhere Bad state: No element

I am running list.firstWhere and this is sometimes throwing an exception: Bad State: No element When the exception was thrown, this was the stack: #0 _ListBase&Object&ListMixin.firstWhere (dart:collection/list.dart:148:5) I do not understand…
creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
195
votes
28 answers

How to hide soft input keyboard on flutter after clicking outside TextField/anywhere on screen?

Currently, I know the method of hiding the soft keyboard using this code, by onTap methods of any widget. FocusScope.of(context).requestFocus(new FocusNode()); But I want to hide the soft keyboard by clicking outside of TextField or anywhere on the…
Ammy Kang
  • 11,283
  • 21
  • 46
  • 68