96,236 questions
671
votes
34
answers
713k
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.
608
votes
19
answers
701k
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 ...
601
votes
41
answers
863k
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?
594
votes
25
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.
542
votes
33
answers
328k
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?
528
votes
36
answers
557k
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.
525
votes
36
answers
413k
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 ...
519
votes
17
answers
215k
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?
510
votes
23
answers
327k
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?
505
votes
29
answers
465k
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 ...
483
votes
25
answers
598k
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 ...
457
votes
20
answers
437k
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 ...
437
votes
28
answers
554k
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 ...
436
votes
38
answers
538k
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 ...
430
votes
22
answers
302k
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 ...
404
votes
32
answers
692k
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 ? ...
390
votes
21
answers
355k
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?
385
votes
24
answers
455k
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".
372
votes
16
answers
163k
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 ...
371
votes
20
answers
438k
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 ...
366
votes
19
answers
159k
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 ...
365
votes
27
answers
342k
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,
...
365
votes
24
answers
267k
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([
...
363
votes
10
answers
261k
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 ...
361
votes
15
answers
379k
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 ...
359
votes
18
answers
393k
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 ...
357
votes
7
answers
65k
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 }) {
...
355
votes
17
answers
570k
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 ...
349
votes
16
answers
398k
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 ...
347
votes
21
answers
347k
views
How do I generate random numbers in Dart?
How do I generate random numbers using Dart?
344
votes
17
answers
145k
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)
...
344
votes
5
answers
81k
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(..)?
342
votes
12
answers
321k
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();
...
336
votes
19
answers
598k
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 ...
334
votes
13
answers
417k
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 ...
332
votes
61
answers
346k
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 ...
330
votes
11
answers
179k
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 ...
327
votes
10
answers
444k
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 ...
322
votes
18
answers
597k
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.
320
votes
13
answers
109k
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....
319
votes
19
answers
290k
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 ...
314
votes
34
answers
364k
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.
313
votes
13
answers
380k
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?
309
votes
30
answers
401k
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....
309
votes
7
answers
114k
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
41
answers
464k
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 ...
300
votes
14
answers
462k
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(
...
299
votes
9
answers
221k
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;
...
298
votes
18
answers
213k
views
Do not use BuildContexts across async gaps
I have noticed a new lint issue in my project.
Long story short:
I need to use BuildContext in my custom classes
flutter lint tool is not happy when this being used with aysnc method.
Example:
...
297
votes
7
answers
149k
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?