How to use BottomNavigationBar with Navigator?

int index = 0; @override Widget build(BuildContext context) { return new Scaffold( body: new Stack( children: <Widget>[ new Offstage( offstage: index != 0, child: new TickerMode( enabled: index == 0, child: new MaterialApp(home: new YourLeftPage()), ), ), new Offstage( offstage: index != 1, child: new TickerMode( enabled: index == 1, child: new MaterialApp(home: new YourRightPage()), … Read more

How can we change appbar background color in flutter

Declare your Color: const primaryColor = Color(0xFF151026); In the MaterialApp level (will change the AppBar Color in the whole app ) change primaryColor return MaterialApp( title: ‘Flutter Demo’, theme: ThemeData( primaryColor: primaryColor, ), home: MyApp(), ); and if you want to change it on the Widget level modify the backgroundColor appBar: AppBar( backgroundColor: primaryColor, ),

Flutter: BottomNavigationBar rebuilds Page on change of tab

None of the previous answers worked out for me. The solution to keep the pages alive when switching the tabs is wrapping your Pages in an IndexedStack. class Tabbar extends StatefulWidget { Tabbar({this.screens}); static const Tag = “Tabbar”; final List<Widget> screens; @override State<StatefulWidget> createState() { return _TabbarState(); } } class _TabbarState extends State<Tabbar> { int … Read more

Flutter: How to open Drawer programmatically

Null safe code Using GlobalKey: final GlobalKey<ScaffoldState> _key = GlobalKey(); // Create a key @override Widget build(BuildContext context) { return Scaffold( key: _key, // Assign the key to Scaffold. drawer: Drawer(), floatingActionButton: FloatingActionButton( onPressed: () => _key.currentState!.openDrawer(), // <– Opens drawer ), ); } Using Builder: @override Widget build(BuildContext context) { return Scaffold( drawer: Drawer(), … Read more

Flutter: “RenderFlex children have non-zero flex but incoming height constraints are unbounded”

Wrap your Column inside an Expanded or SizedBox (with some height) like this: Expanded( child: Column(…) ) OR SizedBox( height: 200, // Some height child: Column(…), ) Note that a Flex class or sub-class (like Column) should not be child of other Flex classes, and their parent class needs to be of type Flexible (i.e. … Read more

How to make button width match parent?

Update: With Flutter 2.0 RaisedButton is deprecated and replaced by ElevatedButton. you can use minimumSize like this: ElevatedButton( style: ElevatedButton.styleFrom( minimumSize: Size.fromHeight(40), // fromHeight use double.infinity as width and 40 is the height ), onPressed: () {}, child: Text(‘Text Of Button’), ) Old answer for Flutter less than 2.0: The correct solution would be to … Read more

Flutter use variable created inside Future builder outside of the build method,

I don’t fully understand the reason to have a global TextController (and I don’t think its a good idea either) but using Riverpod it would look somethink like this: import ‘package:flutter/material.dart’; import ‘package:flutter_riverpod/flutter_riverpod.dart’; class AccountData { final String firstName; final String lastName; final String phoneNumber; AccountData({ required this.firstName, required this.lastName, required this.phoneNumber, }); factory AccountData.fromJson(Map<String, … Read more

Hide Bottom Navigation bar on Scroll in Flutter

This solution is just a workaround to this problem. There may be some detrimental changes. import ‘package:flutter/material.dart’; import ‘package:flutter/rendering.dart’; void main() { runApp(new MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: ‘Flutter Demo’, theme: new ThemeData( primarySwatch: Colors.blue, ), home: new MyHomePage(title: ‘Flutter Demo Home Page’), ); … Read more

Builder versus GlobalKey

The real reason we tend to avoid GlobalKey is not about performance. It is more related to the fact that it breaks a few patterns in flutter. Widgets by definition should not be able to access concrete information of other widgets (such as their size or position). And GlobalKey grant the ability to access such … Read more