95,921
questions
658
votes
33
answers
687k
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.
592
votes
41
answers
842k
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?
588
votes
18
answers
658k
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 ...
578
votes
24
answers
1.1m
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.
522
votes
32
answers
314k
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?
519
votes
36
answers
529k
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.
513
votes
35
answers
394k
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 ...
509
votes
17
answers
206k
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?
500
votes
28
answers
445k
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 ...
495
votes
23
answers
311k
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?
473
votes
25
answers
579k
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 ...
441
votes
20
answers
409k
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 ...
433
votes
28
answers
536k
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 ...
421
votes
20
answers
294k
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 ...
418
votes
37
answers
508k
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 ...
394
votes
32
answers
667k
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 ? ...
383
votes
21
answers
343k
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?
378
votes
24
answers
444k
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".
369
votes
16
answers
159k
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 ...
366
votes
20
answers
425k
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 ...
359
votes
10
answers
256k
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 ...
356
votes
27
answers
333k
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,
...
356
votes
24
answers
254k
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([
...
356
votes
19
answers
152k
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 ...
352
votes
15
answers
363k
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 ...
350
votes
18
answers
379k
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 ...
346
votes
16
answers
550k
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 ...
344
votes
16
answers
390k
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 ...
344
votes
7
answers
63k
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 }) {
...
343
votes
21
answers
334k
views
How do I generate random numbers in Dart?
How do I generate random numbers using Dart?
342
votes
5
answers
79k
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(..)?
341
votes
15
answers
139k
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)
...
335
votes
12
answers
309k
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();
...
332
votes
13
answers
405k
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 ...
325
votes
19
answers
580k
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 ...
323
votes
11
answers
175k
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 ...
320
votes
18
answers
578k
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.
317
votes
10
answers
428k
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 ...
311
votes
59
answers
315k
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 ...
310
votes
34
answers
352k
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.
307
votes
7
answers
110k
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 ...
306
votes
13
answers
102k
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....
305
votes
19
answers
280k
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 ...
305
votes
13
answers
358k
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?
303
votes
31
answers
384k
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....
297
votes
14
answers
446k
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(
...
295
votes
41
answers
439k
views
Visual Studio Code - Target of URI doesn't exist 'package:flutter/material.dart'
I've just set up my Macbook for flutter development,
So I downloaded flutter SDK, and placed it in my Documents. After, I set up my path variable to work with flutter in my command line.
I execute the ...
295
votes
7
answers
147k
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?
294
votes
9
answers
215k
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;
...
291
votes
14
answers
339k
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 ...