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
154
votes
4 answers

Understanding Factory constructor code example - Dart

I have some niggling questions about factory constructors example mentioned here (https://www.dartlang.org/guides/language/language-tour#factory-constructors). I am aware of only three types of constructors on a basic level - default, named and…
Ananta K Roy
  • 1,848
  • 2
  • 14
  • 16
154
votes
11 answers

Dart Multiple Constructors

Is it really not possible to create multiple constructors for a class in dart? in my Player Class, If I have this constructor Player(String name, int color) { this._color = color; this._name = name; } Then I try to add this…
Tom Porat
  • 1,562
  • 2
  • 7
  • 7
154
votes
15 answers

How to show/hide password in TextFormField?

Currently I have my password TextFormField like this: TextFormField( decoration: const InputDecoration( labelText: 'Password', icon: const Padding( padding: const EdgeInsets.only(top: 15.0), child: const…
Farwa
  • 6,156
  • 8
  • 31
  • 46
152
votes
6 answers

Flutter: ListView disable scrolling with touchscreen

Is it possible to let a ListView only be scrollable with the ScrollController and not with the touchscreen?
Tobias Gubo
  • 3,029
  • 5
  • 13
  • 13
152
votes
8 answers

How do I convert a date/time string to a DateTime object in Dart?

Say I have a string "1974-03-20 00:00:00.000" It is created using DateTime.now(), how do I convert the string back to a DateTime object?
Daniel Mana
  • 9,451
  • 13
  • 29
  • 41
151
votes
3 answers

What Does WidgetsFlutterBinding.ensureInitialized() do?

I am trying to use the Firebase package with the below line of code. I really want to know what this line of code actually does? The official documentation didn't help me much. Can someone explain me, please?
Abhishek Ghimire
  • 1,826
  • 2
  • 8
  • 11
150
votes
23 answers

How to implement drop down list in flutter?

I have a list of locations that i want to implement as a dropdown list in Flutter. Im pretty new to the language. Here's what i have done. new DropdownButton( value: _selectedLocation, onChanged: (String newValue) { setState(() { …
Chaythanya Nair
  • 4,774
  • 6
  • 32
  • 40
148
votes
13 answers

How to Deserialize a list of objects from json in flutter

I am using the dart package json_serializable for json serialization. Looking at the flutter documentation it shows how to deserialize a single object as follow: Future fetchPost() async { final response = await…
Gainz
  • 1,639
  • 2
  • 8
  • 10
147
votes
14 answers

Flutter: Find the number of days between two dates

I currently have a user's profile page that brings out their date of birth and other details. But I am planning to find the days before their birthday by calculating the difference between today's date and the date of birth obtained from the…
Asyraf Dayan
  • 2,792
  • 8
  • 26
  • 39
147
votes
15 answers

How can I get the current date (w/o hour and minutes)?

All I can see in the documentation is DateTime.now() but it returns the Timespan also, and I need just the date.
user2070369
  • 3,970
  • 6
  • 22
  • 32
147
votes
9 answers

In Dart is there a quick way to convert int to double?

Very simple issue. I have the useless class: class Useless{ double field; Useless(this.field); } I then commit the mortal sin and call new Useless(0); In checked mode (which is how I run my tests) that blows up, because 'int' is not a subtype…
CarrKnight
  • 2,768
  • 2
  • 23
  • 25
146
votes
38 answers

How to solve SocketException: Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7)

Whenever I try to do an http call after about 20 seconds I get in the console the following error: E/flutter ( 8274): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception: E/flutter ( 8274): SocketException: Failed host…
David
  • 1,503
  • 2
  • 6
  • 7
146
votes
7 answers

Flutter StreamBuilder vs FutureBuilder

What is the main difference between StreamBuilder and FutureBuilder. What to use and when to use? What are the tasks they are intended to perform? How each of them listens to changes in a dynamic list?
146
votes
12 answers

Iterating through a list to render multiple widgets in Flutter?

I have a list of strings defined like this: var list = ["one", "two", "three", "four"]; I want to render the values on the screen side by side using text widgets. I have attempted to use the following code to attempt this: for (var name in list)…
rakeshdas
  • 2,363
  • 5
  • 20
  • 28
146
votes
21 answers

How can I clone an Object (deep copy) in Dart?

Is there a Language supported way to make a full (deep) copy of an Object in Dart? If multiple options exist, what are their differences?
george koller
  • 3,721
  • 6
  • 23
  • 27