Horizontally scrollable cards with Snap effect in flutter

Use PageView and ListView: import ‘package:flutter/material.dart’; main() => runApp(MaterialApp(home: MyHomePage())); class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(‘Carousel in vertical scrollable’), ), body: ListView.builder( padding: EdgeInsets.symmetric(vertical: 16.0), itemBuilder: (BuildContext context, int index) { if(index % 2 == 0) { return _buildCarousel(context, index ~/ 2); } else { … Read more

How can I add shadow to the widget in flutter?

Check out BoxShadow and BoxDecoration A Container can take a BoxDecoration (going off of the code you had originally posted) which takes a boxShadow return Container( margin: EdgeInsets.only(left: 30, top: 100, right: 30, bottom: 50), height: double.infinity, width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(10), topRight: Radius.circular(10), bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10) ), boxShadow: … Read more

How to create a dynamic TabBarView/ Render a new Tab with a function in Flutter?

Problems arise if you need to modify the arrays. They consist in the fact that when modifying an array you do not have the opportunity to use the same controller. You can use the next custom widget for this case: import ‘package:flutter/material.dart’; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget … Read more

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

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: “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 shift focus to the next TextField in Flutter?

Screenshot: Just use: textInputAction: TextInputAction.next: To move the cursor to the next field. textInputAction: TextInputAction.done: To close the keyboard. @override Widget build(BuildContext context) { return Scaffold( body: Column( children: <Widget>[ TextField( decoration: InputDecoration(hintText: ‘TextField A’), textInputAction: TextInputAction.next, // Moves focus to next. ), TextField( decoration: InputDecoration(hintText: ‘TextField B’), textInputAction: TextInputAction.next, // Moves focus to next. … 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