Yellow lines under Text Widgets in Flutter?

The problem is having a Scaffold or not. Scaffold is a helper for Material apps (AppBar, Drawer, that sort of stuff). But you’re not forced to use Material. What you’re missing is an instance of DefaultTextStyle as a parent: DefaultTextStyle( style: TextStyle(…), child: Text(‘Hello world’), ) Various widgets add one to change the default text … Read more

How do I Set Background image in Flutter?

I’m not sure I understand your question, but if you want the image to fill the entire screen you can use a DecorationImage with a fit of BoxFit.cover. class BaseLayout extends StatelessWidget{ @override Widget build(BuildContext context){ return Scaffold( body: Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage(“assets/images/bulb.jpg”), fit: BoxFit.cover, ), ), child: null /* add child … Read more

How to show/hide widgets programmatically in Flutter

Definition: Invisible: The widget takes up physical space on the screen but is not visible to user. This can be achieved using Visibility widget. Gone: The widget doesn’t take up any physical space and is completely gone. This can be achieved using Visibility, if or if-else condition. Invisible example: Visibility( child: Text(“Invisible”), maintainSize: true, maintainAnimation: … Read more

How to deal with unwanted widget build?

The build method is designed in such a way that it should be pure/without side effects. This is because many external factors can trigger a new widget build, such as: Route pop/push Screen resize, usually due to keyboard appearance or orientation change The parent widget recreated its child An InheritedWidget the widget depends on (Class.of(context) … Read more

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

(I assume you’re using a Row because you want to put other widgets beside the TextField in the future.) The Row widget wants to determine the intrinsic size of its non-flexible children so it knows how much space that it has left for the flexible ones. However, TextField doesn’t have an intrinsic width; it only … Read more

How to create Toast in Flutter

UPDATE: Scaffold.of(context).showSnackBar is deprecated in Flutter 2.0.0 (stable) You can access the parent ScaffoldMessengerState using ScaffoldMessenger.of(context). Then do something like ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text(“Sending Message”), )); Snackbars are the official “Toast” from material design. See Snackbars. Here is a fully working example: import ‘package:flutter/material.dart’; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget … Read more

What is the difference between functions and classes to create reusable widgets?

Edit: The Flutter team has now taken an official stance on the matter and stated that classes are preferable. See https://www.youtube.com/watch?v=IOyq-eTRhvo TL;DR: Prefer using classes over functions to make reusable widget-tree. EDIT: To make up for some misunderstanding: This is not about functions causing problems, but classes solving some. Flutter wouldn’t have StatelessWidget if a … Read more