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.

Filter by
Sorted by
Tagged with
611 votes
34 answers
601k views

How do I use hexadecimal color strings in Flutter?

How do I convert a hexadecimal color string like #b74093 to a Color in Flutter? I want to use a HEX color code in Dart.
creativecreatorormaybenot's user avatar
555 votes
38 answers
757k views

Create a rounded button / button with border-radius in Flutter

I'm currently developing an Android app in Flutter. How can I add a rounded button?
Kingsley CA's user avatar
  • 10.7k
550 votes
14 answers
557k views

How to change the application launcher icon on Flutter?

When I create an app with a flutter create command, the flutter logo is used as an application icon for both platforms. If I want to change the app icon, shall I go to both platforms directories and ...
RobertoAllende's user avatar
542 votes
18 answers
930k views

How can I add a border to a widget in Flutter?

I'm using Flutter and I'd like to add a border to a widget (in this case, a Text widget). I tried TextStyle and Text, but I didn't see how to add a border.
Seth Ladd's user avatar
  • 113k
486 votes
27 answers
274k views

How do you build a Singleton in Dart?

The singleton pattern ensures only one instance of a class is ever created. How do I build this in Dart?
Seth Ladd's user avatar
  • 113k
480 votes
34 answers
438k views

How to change package name in flutter?

Is there any way to change Package Name of Flutter project? I want to change package name and application name in flutter project.
Abc Xyz's user avatar
  • 5,937
480 votes
17 answers
184k views

What is the difference between the "const" and "final" keywords in Dart?

What is the difference between the const and final keywords in Dart?
Ishmal Ijaz's user avatar
  • 5,337
472 votes
33 answers
333k views

How can I dismiss the on screen keyboard?

I am collecting user input with a TextFormField and when the user presses a FloatingActionButton indicating they are done, I want to dismiss the on screen keyboard. How do I make the keyboard go away ...
Collin Jackson's user avatar
468 votes
28 answers
374k views

No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase

I am building a Flutter application and I have integrated Firebase, but I keep getting this error when I click on a button either to register, login, or logout. I have seen other people have asked the ...
Kennedy Owusu's user avatar
449 votes
20 answers
258k views

How do you detect the host platform from Dart code?

For UI that should differ slightly on iOS and Android, i.e. on different platforms, there must be a way to detect which one the app is running on, but I couldn't find it in the docs. What is it?
Gavin's user avatar
  • 6,545
436 votes
24 answers
503k views

Flutter - Wrap text on overflow, like insert ellipsis or fade

I'm trying to create a line in which center text has a maximum size, and if the text content is too large, it fits in size. I insert the TextOverflow.ellipsis property to shorten the text and ...
rafaelcb21's user avatar
  • 12.5k
412 votes
27 answers
468k views

How to create number input field in Flutter?

I'm unable to find a way to create an input field in Flutter that would open up a numeric keyboard and should take numeric input only. Is this possible with Flutter material widgets? Some GitHub ...
Janne Annala's user avatar
  • 26.1k
390 votes
20 answers
335k views

How can I change the app display name build with Flutter?

I have created the app using Flutter create testapp. Now, I want to change the app name from "testapp" to "My Trips Tracker". How can I do that? I have tried changing from the ...
rajaishwary's user avatar
  • 4,392
389 votes
18 answers
261k views

How to add a ListView to a Column in Flutter?

I'm trying to construct a simple login page for my Flutter app. I've successfully built the TextFields and log in/Sign in buttons. I want to add a horizontal ListView. When I run the code my ...
Charles Jr's user avatar
  • 8,383
374 votes
35 answers
432k views

Dart SDK is not configured

I installed Flutter and set up Android Studio. Then I cloned an example of flutter on GitHub (https://github.com/flutter/flutter) and launched it in Android Studio, but it warns me "Dart SDK is ...
Katelyn's user avatar
  • 3,751
365 votes
20 answers
302k views

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's user avatar
  • 113k
360 votes
32 answers
583k views

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 ? ...
Marko's user avatar
  • 4,897
357 votes
24 answers
397k views

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's user avatar
  • 113k
354 votes
16 answers
147k views

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 ...
Figen Güngör's user avatar
345 votes
18 answers
374k views

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 ...
Luke's user avatar
  • 6,418
345 votes
8 answers
234k views

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 ...
moonvader's user avatar
  • 19.9k
333 votes
24 answers
216k views

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([ ...
boeledi's user avatar
  • 6,897
330 votes
14 answers
118k views

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.<init>(SchemaModule.java:156) ...
Vivek Kogilathota's user avatar
326 votes
27 answers
293k views

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, ...
pallav bohara's user avatar
326 votes
16 answers
132k views

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 ...
dasfima's user avatar
  • 4,871
322 votes
17 answers
330k views

How do I disable a Button in Flutter?

I'm having trouble figuring out how to set the enabled state of a button in Flutter. 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 ...
chris84948's user avatar
  • 3,950
319 votes
15 answers
314k views

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 ...
KingLagalot's user avatar
  • 3,234
317 votes
16 answers
354k views

How to show/hide widgets programmatically in Flutter

In Android, every single View subclass has a setVisibility() method that allows you modify the visibility of a View object There are 3 options of setting the visibility: Visible: Renders the View ...
user3217522's user avatar
  • 5,836
317 votes
5 answers
72k views

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's user avatar
  • 9,491
317 votes
19 answers
299k views

How do I generate random numbers in Dart?

How do I generate random numbers using Dart?
Seth Ladd's user avatar
  • 113k
317 votes
6 answers
56k views

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 }) ...
Rémi Rousselet's user avatar
314 votes
12 answers
355k views

Flutter: how to make a TextField with HintText but no Underline?

This is what I'm trying to make: In the Flutter docs for Text Fields (https://flutter.io/text-input/) it says you can remove the underline by passing null to the decoration. However, that also gets ...
juan park's user avatar
  • 3,254
308 votes
11 answers
159k views

TextField inside of Row causes layout exception: Unable to calculate size

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 ...
Matthew Smith's user avatar
305 votes
9 answers
264k views

setState() or markNeedsBuild called during build

class MyHome extends StatefulWidget { @override State<StatefulWidget> createState() => new MyHomePage2(); } class MyHomePage2 extends State<MyHome> { List items = new List(); ...
Divyang Shah's user avatar
  • 3,587
304 votes
32 answers
305k views

How to create Toast in Flutter

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.
Shady Aziza's user avatar
  • 51.1k
303 votes
19 answers
513k views

How do I Set Background image in Flutter?

I am trying to set a background image for the home page. I am getting the image place from start of the screen and filling the width but not the height. Am I missing something in my code? Are there ...
Arun Kumar's user avatar
  • 3,271
301 votes
10 answers
479k views

Flutter- wrapping text

I want wrap text as text grows. I searched through and tried wrap with almost everything but still text stays one line and overflows from the screen. Does anyone know how to achieve this? Any help is ...
Daibaku's user avatar
  • 11.5k
298 votes
6 answers
99k views

How to deal with unwanted widget build?

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 ...
Rémi Rousselet's user avatar
296 votes
10 answers
372k views

How to run code after some delay in Flutter?

I'd like to execute a function after a certain delay after my Widget is built. What's the idiomatic way of doing this in Flutter? What I'm trying to achieve: I'd like to start with a default ...
Bradley Campbell's user avatar
295 votes
16 answers
503k views

How can I add shadow to the widget in flutter?

How can I add shadow to the widget like in the picture below? This is my current widget code.
Mohammed Mustafa's user avatar
286 votes
28 answers
328k views

How do you round a double in Dart to a given degree of precision AFTER the decimal point?

Given a double, I want to round it to a given number of points of precision after the decimal point, similar to PHP's round() function. The closest thing I can find in the Dart docs is double....
Lucas Meadows's user avatar
285 votes
7 answers
139k views

What is the difference between named and positional parameters in Dart?

Dart supports both named optional parameters and positional optional parameters. What are the differences between the two? Also, how can you tell if an optional parameter was actually specified?
Seth Ladd's user avatar
  • 113k
283 votes
16 answers
244k views

Multi-line TextField in Flutter

It may sound easy but How can we do a multi-line editable textfield in flutter? TextField works only with a single line. Edit: some precisions because seems like it's not clear. While you can set ...
Rémi Rousselet's user avatar
280 votes
12 answers
83k views

How can I check if a Flutter application is running in debug?

I'm looking for a way to execute code in Flutter when the app is in Debug mode. Is that possible in Flutter? I can't seem to find it anywhere in the documentation. Something like this If(app....
Kevin Walter's user avatar
  • 6,557
280 votes
12 answers
301k views

How do I parse a string into a number with Dart?

I would like to parse strings like 1 or 32.23 into integers and doubles. How can I do this with Dart?
Seth Ladd's user avatar
  • 113k
275 votes
14 answers
304k views

The equivalent of wrap_content and match_parent in flutter?

In Android match_parent and wrap_content are used to resize the widgets automatically relative to their parent to the content the widget contains. In Flutter it seems by default all widgets are set ...
Faisal Abid's user avatar
  • 8,900
275 votes
8 answers
193k views

Passing Data to a Stateful Widget in Flutter

I'm wondering what the recommended way of passing data to a stateful widget, while creating it, is. The two styles I've seen are: class ServerInfo extends StatefulWidget { Server _server; ...
Mojachiee's user avatar
  • 2,869
270 votes
13 answers
115k views

Flutter: Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized

Any solution to solve this problem? Stacktrace: [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized. If you'...
Sopheadavid Sopheap's user avatar
269 votes
52 answers
240k views

Flutter and google_sign_in plugin: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

The dialog (Google form) for the credentials is opened successfully, but after I fill my credentials I'm getting this error. I followed the instructions from here. Created a Firebase project, enabled ...
Boyan Bozhidarov's user avatar
266 votes
14 answers
380k views

Flutter give container rounded border

I'm making a Container(), I gave it a border, but it would be nice to have rounded borders. This is what I have now: Container( width: screenWidth / 7, decoration: BoxDecoration( ...
Karel Debedts's user avatar

1
2 3 4 5
1845