Flutter how to have multiple Lists - flutter

i am beginner in flutter , i created a widget that displays a player informations , i used ListView and ListView.builder but i had an uknown error that said : Failed assertion: line 1785 pos 12: 'hasSize' and Vertical viewport was given unbounded height.
i do not know what is the source of this error , it started only when i added the ListView builder , before i add it everything was working fine
here what i have tried:
import 'package:flutter/material.dart';
import 'package:tl_fantasy/widgets/Player_Widget.dart';
import 'player_arguments.dart';
class PlayerDetails extends StatelessWidget {
#override
Widget build(BuildContext context) {
final PlayerArguments args = ModalRoute.of(context).settings.arguments;
List<Stats> stats = [
Stats("Matches", args.matches ),
Stats("Goals", args.goals ),
Stats("Assists", args.assists ),
Stats("Saves", args.saves ),
];
List<Team> teams = [
Team("Barcelona B", "https://i.pinimg.com/originals/ef/9c/3f/ef9c3fccec423f70376fcafa05c5d447.jpg","1998" ),
Team("Barcelona", "https://i.pinimg.com/originals/ef/9c/3f/ef9c3fccec423f70376fcafa05c5d447.jpg","2005" ),
];
return Scaffold(
appBar: AppBar(
title: Text("Player Details"),
backgroundColor: Colors.blue[300],
elevation: 0.0,
),
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.purple, Colors.blue])
),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.purple, Colors.black38])),
child: ListView(
children: [
SizedBox(
height: 20,
),
Container(
width: double.infinity,
child: Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child:
Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(args.image),
),
const SizedBox(width:10.0),
Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget> [
Text(args.name, style: TextStyle( fontWeight:FontWeight.bold,
fontSize: 18.0,
)),
const SizedBox(height: 5.0, ),
Text(args.club, style: TextStyle( fontWeight:FontWeight.bold,
fontSize: 18.0,
)),
const SizedBox(height: 5.0, ),
Text("Role : "+args.role, style: TextStyle( fontWeight:FontWeight.bold,
fontSize: 18.0, color: Colors.grey[600],
)),
const SizedBox(height: 5.0, ),
Text("Position : "+args.club, style: TextStyle( fontWeight:FontWeight.bold,
fontSize: 18.0, color: Colors.grey[600],
)),
const SizedBox(height: 5.0, ),
Text("Nationality : "+args.nationality, style: TextStyle( fontWeight:FontWeight.bold,
fontSize: 18.0, color: Colors.grey[600],
)),
],
),
],
),
),
),
),
Container(
padding: EdgeInsets.all(12.0),
child: GridView.builder(
shrinkWrap: true,
itemCount: stats.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0
),
itemBuilder: (BuildContext context, int index){
return Card(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
alignment: Alignment.topCenter,
padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
child: Text(stats[index].result,style: TextStyle(fontSize: 20.0)),
),
Container(
alignment: Alignment.bottomCenter,
child: Text(stats[index].title,style: TextStyle(fontSize: 25.0)),),
]
),
),
);
},
)
),
SizedBox(
height: 30,
),
Container(child:
ListView.builder(
itemBuilder: (context, index){
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child:
Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(teams[index].image),
),
const SizedBox(width:10.0),
Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget> [
Text(teams[index].name, style: TextStyle( fontWeight:FontWeight.bold,
fontSize: 18.0,
)),
const SizedBox(height: 5.0, ),
Text("joined : "+teams[index].date, style: TextStyle( fontWeight:FontWeight.bold,
fontSize: 18.0, color: Colors.grey[600],
)),
],
),
],
),
),
);
},
itemCount: teams.length,
),),
],
),
),
),
);
}
}
class Stats{
String title;
String result;
Stats(this.title,this.result);
}
class Team {
String name;
String image;
String date;
Team(this.name,this.image,this.date);
}
I am trying to know what happened and how to solve the error after i added the ListView.builder

Change this:
Container(child:
ListView.builder(
itemBuilder: (context, index){
return Card(
to this:
Flexible(child:
ListView.builder(
shrinkwrap: true,
itemBuilder: (context, index){
return Card(
This is caused because you're using a listviewbuilder inside a column, and both expand in the same direction, flutter doesn't know when to stop laying out the listview. If Flexible doesn't work, use expanded instead, and keep the shrink wrap.

Use a CustomScrollView with SliverList and/or SliverGrid for multiple scrolling list in the same widget.

Try adding shrinkWrap: true inside listView.builder
--UPDATE--
You can disable the scroll of the child scrollable widget if its parent is already scrollable.
children: [
ListView.builder(
...
physics: NeverScrollableScrollPhysics(),
...
)
...

Related

How to set number of elements to show in a CarouselSlider per page, using carousel_slider in flutter

I'm creating a vertical carousel slider using carousel_slider but there's a huge empty space between elements and I can't display the previous element on the screen. What is the best way to remove the empty space and also show the previous element.
My screen is set as follows
Column(
children: [
Container(
margin: const EdgeInsets.fromLTRB(16, 16, 16, 16),
child: TextField(
controller: controller,
),
),
//Carousel built here
Expanded(
child: CarouselSlider.builder(
itemCount: cars.length,
itemBuilder: (context, index, pageViewIndex) => CarTile(
car: cars[index],
onpress: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
CarDetailsScreen(car: cars[index]))),
),
options: CarouselOptions(
scrollDirection: Axis.vertical,
enlargeCenterPage: true,
),
),
),
],
);
CarTile code is as follows:
class CarTile extends StatelessWidget {
final Car car;
final VoidCallback onpress;
const CarTile({super.key, required this.onpress, required this.car});
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return GestureDetector(
onTap: onpress,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
child: Column(
children: [
Image.network(
height: 150,
width: size.width,
fit: BoxFit.fitWidth,
car.image,
),
const SizedBox(
height: 5,
),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(5)),
child: Text(
car.features[0],
style: const TextStyle(fontWeight: FontWeight.w500),
),
),
const SizedBox(
width: 5,
),
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(5)),
child: Text(
car.features[1],
style: const TextStyle(fontWeight: FontWeight.w500),
),
),
],
),
),
Row(
children: [
Text(
'${car.brand} ${car.model}',
style: const TextStyle(fontWeight: FontWeight.w900),
),
const Spacer(),
Text(
'Tsh. ${NumberFormat.decimalPattern().format(car.price)} / hr',
style: const TextStyle(fontWeight: FontWeight.w900),
),
],
),
Align(alignment: Alignment.centerLeft, child: Text('${car.year}'))
],
),
),
);
}
}
And this is my current results

ListView.builder is not scrolling in flutter

i'm trying to integrate a listView.builder in my UI! First of all, the whole content of the screen is inside a CustomScrollView that has silver widgets inside of it. Everything works pretty fine unless that my listview is not scrolling.
Here is the code:
class _DashboardScreenState extends State<DashboardScreen> {
#override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
return Scaffold(
appBar: CustomAppBar(),
body: CustomScrollView(
physics: ClampingScrollPhysics(),
slivers: <Widget>[
_buildHeader(screenHeight),
_buildBody(screenHeight),
],
),
);
}
}
The _buildBody code:
SliverToBoxAdapter _buildBody(double screenHeight) {
return SliverToBoxAdapter(
child: Column(
children: [
Container(
width: 100,
height: 65,
child: Padding(
padding: const EdgeInsets.only(top: 20),
child: ElevatedButton(
onPressed: () {},
child: Text(
'Add',
style: TextStyle(fontSize: 18),
),
style: ElevatedButton.styleFrom(
shape: StadiumBorder(),
backgroundColor: Palette.primaryColor),
),
),
),
SizedBox(
height: 10,
),
ListView.builder(
scrollDirection: Axis.vertical,
physics: const AlwaysScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: 6,
itemBuilder: ((BuildContext context, int index) {
return Container(
margin: const EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 20.0,
),
padding: const EdgeInsets.all(10.0),
height: screenHeight * 0.15,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFFAD9FE4), Palette.primaryColor],
),
borderRadius: BorderRadius.circular(20.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Image.asset(
"assets/worker.png",
height: 80,
width: 80,
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Somme: 50 €',
style: const TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: screenHeight * 0.01),
Text(
'Date: 19 novembre 2022',
style: TextStyle(fontSize: 10, color: Colors.white),
),
SizedBox(height: screenHeight * 0.01),
Text(
'Follow the instructions\nto do your own test.',
style: const TextStyle(
color: Colors.white,
fontSize: 16.0,
),
maxLines: 2,
),
],
)
],
),
);
}))
],
),
);
}
I tried adding shrinkWrap: true as well as the scroll direction. Also tried wrapping it inside a SingleScrollChildView, none of the solutions worked for me. I appreciate any kind of help!
You can use physics: const NeverScrollableScrollPhysics(), on listView, the parent widget is already handling the scroll event. But you can replace listView with Column widget.(we already have on parent, therefor using loop)
SliverToBoxAdapter _buildBody(double screenHeight) {
return SliverToBoxAdapter(
child: Column(
children: [
Container(
width: 100,
height: 65,
child: Padding(
padding: const EdgeInsets.only(top: 20),
child: ElevatedButton(
onPressed: () {},
child: Text(
'Add',
style: TextStyle(fontSize: 18),
),
style: ElevatedButton.styleFrom(
shape: StadiumBorder(),
backgroundColor: Palette.primaryColor),
),
),
),
SizedBox(
height: 10,
),
for (int i = 0; i < 6; i++)
Container(
margin: const EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 20.0,
),
padding: const EdgeInsets.all(10.0),
height: screenHeight * 0.15,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFFAD9FE4), Palette.primaryColor],
),
borderRadius: BorderRadius.circular(20.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Image.asset(
"assets/worker.png",
height: 80,
width: 80,
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Somme: 50 €',
style: const TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: screenHeight * 0.01),
Text(
'Date: 19 novembre 2022',
style: TextStyle(fontSize: 10, color: Colors.white),
),
SizedBox(height: screenHeight * 0.01),
Text(
'Follow the instructions\nto do your own test.',
style: const TextStyle(
color: Colors.white,
fontSize: 16.0,
),
maxLines: 2,
),
],
)
],
),
)
],
),
);
}
Instead of using ListView.Builderinside CustomScrollView. It is always better to use Slivers. Therefore, instead of wrapping ListView.builder with SliverToBoxAdapter, use SliverList. Here is the detail code I have refactored below for you. Or you can directly visit this link where you can play with the refactored code.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(),
home: const DashboardScreen(),
debugShowCheckedModeBanner: false,
);
}
}
class DashboardScreen extends StatefulWidget {
const DashboardScreen({super.key});
#override
State<DashboardScreen> createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
#override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
return Scaffold(
appBar: AppBar(),
body: CustomScrollView(
physics: ClampingScrollPhysics(),
slivers: <Widget>[
// your build header widget
SliverToBoxAdapter(
child: Container(
width: 100,
height: 65,
child: Padding(
padding: const EdgeInsets.only(top: 20),
child: ElevatedButton(
onPressed: () {},
child: Text(
'Add',
style: TextStyle(fontSize: 18),
),
style: ElevatedButton.styleFrom(
shape: StadiumBorder(),
backgroundColor: Colors.red,
),
),
),
),
),
SliverToBoxAdapter(
child: SizedBox(height: 10),
),
SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return Container(
margin: const EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 20.0,
),
padding: const EdgeInsets.all(10.0),
height: screenHeight * 0.15,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFFAD9FE4), Colors.red],
),
borderRadius: BorderRadius.circular(20.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
// Image.asset(
// "assets/worker.png",
// height: 80,
// width: 80,
// ),
//
Container(
height: 80,
width: 80,
child: Text("A"),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Somme: 50 €',
style: const TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: screenHeight * 0.01),
Text(
'Date: 19 novembre 2022',
style: TextStyle(fontSize: 10, color: Colors.white),
),
SizedBox(height: screenHeight * 0.01),
Text(
'Follow the instructions\nto do your own test.',
style: const TextStyle(
color: Colors.white,
fontSize: 16.0,
),
maxLines: 2,
),
],
)
],
),
);
}),
)
],
),
);
}
}

Error:RenderBox was not laid out: NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

i am having problem using SingleChildScrollView in this way, i dont no what is wrong, i keep getting this error.
If add the SingleChildScrollView the page will be blank(will not show all the widget)but if i remove the SingleChildScrollView, the page will show.
RenderBox was not laid out: RenderPadding#583c0 relayoutBoundary=up1
NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart': Failed assertion: line 1929
pos 12: 'hasSize
The relevant error-causing widget was Scaffold
Scaffold:file:///Users/mac/Documents/Uneleap-Platform-master/lib/screens/Pages/forum/forum.dart:25:12
here is the code
SafeArea(
minimum: EdgeInsets.only(left: 25.0, right: 20.0, top: 10.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
WidgetForum(
details: 'The Get Is Not Geting together ?',
name: 'Nina Simon',
url: 'assets/dashboard_pic.png',
),
SizedBox(
height: 5,
),
WidgetForum(
details:
'''Notes is designed for whatever’s on your mind.\nJot down your thoughts. Download Notes.\nThere is something wonderful in writing. \nThe Get Is Not Getting Together?''',
name: 'James Nugar',
url: 'assets/dashboard_pic.png',
),
Text(
'Topics',
style: TextStyle(
fontSize: 35,
),
),
Expanded(
child: ListView.separated(
scrollDirection: Axis.horizontal,
separatorBuilder: (_, inedex) => SizedBox(
width: 20,
),
itemCount: topics.length,
itemBuilder: (context, index) {
return Container(
height: 50,
width: 100,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(15),
image: DecorationImage(
image: AssetImage('assets/saved_2.png'),
fit: BoxFit.fill,
),
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(
topics[index].schoolNmae!,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
)
],
),
);
}),
),
WidgetForum(
details:
'''Notes is designed for whatever’s on your mind.\nJot down your thoughts. Download Notes.\nThere is something wonderful in writing. \nThe Get Is Not Getting Together?''',
name: 'Sam Ajayi',
url: 'assets/dashboard_pic.png',
),
],
),
),
),
// bottomSheet:
floatingActionButton: FloatingActionButton(
onPressed: () {
Scaffold.of(context).showBottomSheet<void>((BuildContext context) {
return Container(
height: 250,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 50,
horizontal: 15.0,
),
child: Column(
children: [
Row(
children: [
Icon(
CustomIcons.answers_forum,
color: Colors.grey,
),
SizedBox(
width: 10,
),
Text(
'Post',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
Padding(
padding: const EdgeInsets.only(right: 120.0),
child: Divider(
thickness: 2,
color: Colors.white,
),
),
Row(
children: [
Icon(
CustomIcons.create_forum,
color: Colors.grey,
),
SizedBox(
width: 10,
),
Text(
'Create Forum',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
Align(
alignment: Alignment.bottomRight,
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Container(
height: 70,
width: 70,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Center(
child: Icon(Icons.add),
),
),
),
)
],
),
),
);
});
},
child: Icon(Icons.add),
),
);
}
}
class WidgetForum extends StatefulWidget {
final String? name;
final String? details;
final String? url;
WidgetForum(
{Key? key, required this.name, required this.details, required this.url})
: super(key: key);
#override
_WidgetForumState createState() => _WidgetForumState();
}
class _WidgetForumState extends State<WidgetForum> {
#override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
height: 50,
width: 50,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.url!),
fit: BoxFit.fill,
),
),
),
SizedBox(
width: 5,
),
Text(
widget.name!,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25),
)
],
),
PopupMenuButton(
color: Colors.black,
offset: Offset(0, 40),
itemBuilder: (_) => <PopupMenuItem<String>>[
new PopupMenuItem<String>(
child: Center(
child: Text(
'Fellow',
style: TextStyle(
color: Colors.white,
),
),
),
),
new PopupMenuItem<String>(
child: Center(
child: Text(
'Block',
style: TextStyle(
color: Colors.white,
),
),
),
),
new PopupMenuItem<String>(
child: Center(
child: Text(
'Report',
style: TextStyle(
color: Colors.white,
),
),
),
),
],
child: Container(
height: 20,
width: 20,
child: SvgPicture.asset('assets/library_pre.svg'),
),
),
],
),
SizedBox(height: 18),
Text(
widget.details!,
style: TextStyle(fontSize: 15),
),
SizedBox(height: 18),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
CustomIcons.icons8_up_2_11,
color: Colors.red,
),
Text('36'),
Icon(
CustomIcons.icons8_down,
color: Colors.grey,
),
Icon(
CustomIcons.answers_forum,
color: Colors.grey,
),
Text('3')
],
),
Text('Sep 2, 2020')
],
),
Divider(
thickness: 1,
)
],
);
}
}
You cannot use Expanded in Column if it has a parent SingleChildScrollView because When you use column it tries to be in screen height and when use expanded inside, The column will allocate remaining space to the child of the expanded widget, Now if you use SingleChildScrollView It will try to expand(by direction, vertically in your case) as long as possible but as you're using the Expanded which tries to take remaining space, So it goes infinite thus throws that error,
So Either remove SingleChildScrollView and use Column and expanded or remove the Expanded and Use SingleChildScrollView also make sure ShrinkWrap in ListView to true.
Column(
children: [
Text(
'Hello, World!',
style: Theme.of(context).textTheme.headline4,
),
Container(
height: 50,
width: 200,
color: Colors.amber,
child: const Text('Random widget'),
),
Expanded(
child: ListView.separated(
shrinkWrap: true,
itemCount: 20,
separatorBuilder: (_, __) => const Divider(),
itemBuilder: (context, int index) {
return ListTile(
title: Text('Item at $index'),
);
},
),
)
],
);
Or to Scroll all the widgets You can do using SingleChildScrollView
Remove the Expanded widget here.
SingleChildScrollView(
child: Column(
children: [
Text(
'Hello, World!',
style: Theme.of(context).textTheme.headline4,
),
Container(
height: 50,
width: 200,
color: Colors.amber,
child: const Text('Random widget'),
),
ListView.separated(
shrinkWrap: true,
itemCount: 20,
separatorBuilder: (_, __) => const Divider(),
itemBuilder: (context, int index) {
return ListTile(
title: Text('Item at $index'),
);
},
),
],
),
);
Wrap it in a Container and add a height to it.
Fixed it for me.
I solved the issue by enclosing the Column widget in a Container widget that has a set width and height
You cannot use Expanded in Column if it has a parent SingleChildScrollView because When you use column it tries to be in screen height and when use expanded inside, The column will allocate remaining space to the child of the expanded widget, Now if you use SingleChildScrollView It will try to expand(by direction, vertically in your case) as long as possible but as you're using the Expanded which tries to take remaining space, So it goes infinite thus throws that error,
So Either remove SingleChildScrollView and use Column and expanded or remove the Expanded and Use SingleChildScrollView also make sure ShrinkWrap in ListView to true.
I have found the same problem. but in my case I was trying to provide row of widgets
for trailing property of the listTile class .and I solve it by wrapping the row with container and set its width.
In one case, I got the same error.
When I scrolled to top of the log message, I found out the issue in below widget.I have wrapped the Row with IntrinsicHeight widget.
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: []));
On removing IntrinsicHeight widget, it solved.

How to make fixed button flutter?

I have a problem with fixed button inside scroll view , I made a column with SingleChildScrollView and two button, but the problem is that the screen do not scroll. I tried the bottom Navigation bar but it has the same problem. How I can fix this?
my code :
Column(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [
ListView.builder(
shrinkWrap: true,
itemCount: 200,
itemBuilder: (context, index) {
return Text("200");
},
),
ListView.builder(
shrinkWrap: true,
itemCount: 20,
itemBuilder: (context, index) {
return Text("bargougui");
},
),
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
width: 150,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.grey[300],
),
onPressed: () {},
child: Text(
'Contacter',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.black,
fontStyle: FontStyle.italic,
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
width: 150,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.yellow,
),
onPressed: () {},
child: Text(
'Acheter',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.black,
fontStyle: FontStyle.italic,
),
),
),
),
),
),
],
),
],
),
screen I want to make like this
any help will be appreciated ^^
Use Stack widget,
Stack(
children:[
SingleChildScrollView(),
Positioned(
bottom:0,
left:15,
right:15,
child:Row(children :[Button1(),Button2()],
,)
]
Try tweaking the numbers to fit your case.

Flutter: How to control a PageView by GetxController?

Subject: PageView and GetX
I'm having trouble detaching the controls on a PageView widget from the HomeView module. I have a GlobalController with its respective GlobalBinding that are instantiated when opening the HomeView. I would like to take the setPage(int page) method to the GlobalController that would eventually make the HomeView's PageView change pages. I don't know how to get PageController from PageView to GlobalController in order to make it work. How should I proceed?
Something Like this?
am using pageview in onboarding
class Onboard{
final headTitle;
final secondarytitle;
final discription;
final pngimage;
Onboardslist(this.headTitle, this.secondarytitle, this.discription, this.pngimage);
}
then for the controller
class OnboardController extends GetxController{
var selectedPagexNumber = 0.obs;
bool get isLastPage => selectedPagexNumber.value == onBoardPages.length -1;
var pageControll = PageController();
forwardAct()
{
if(isLastPage) Get.offNamedUntil(signin, (route)=> false);
else pageControll.nextPage(duration: 300.milliseconds, curve: Curves.ease);
}
List<Onboardslist> onBoardPages =
[
Onboardslist("title",
"short description",
"long description",
imageString),
Onboardslist("title",
"short description",
"long description",
imageString),
Onboardslist("title",
"short description",
"long description",
imageString),
Onboardslist("title",
"short description",
"long description",
imageString)
];
}
then for the view i did was simply like this
class Onboarding extends StatelessWidget {
final yourController= OnboardController();
#override
Widget build(BuildContext context) {
SizeXGet().init(context);
return Scaffold(
backgroundColor: decent_white,
appBar: AppBarCustom(
title: 'Skip',
button: ()=>Get.offNamedUntil(signin,(route)=>false),
),
body: WillPopScope(
onWillPop: () async => false,
child: SafeArea(
child: Stack(
children: [
PageView.builder(
controller: yourController.pageControll,
onPageChanged: yourController.selectedPagexNumber,
itemCount: yourController.onBoardPages.length,
itemBuilder: (context, index)
=>Padding(
padding: const EdgeInsets.only(left: 10,right: 10),
child: Container(
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: getHeight(150),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(left: 20,right: 20),
child: Text(yourController.onBoardPages[index].headTitle,
style: TextStyle(
color: darkish_color,
fontSize: getHeight(20),
fontFamily: 'Metropolis-SemiBold' ,
fontWeight: FontWeight.bold
),),
),
SizedBox(height: 15,),
Padding(
padding: const EdgeInsets.only(left: 50,right: 50),
child: Text(yourController.onBoardPages[index].secondarytitle,
style: TextStyle(
color: not_sopure_black,
fontSize: getHeight(26),
fontFamily: 'Metropolis-Bold' ,
fontWeight: FontWeight.bold
),
),
),
SizedBox(height: 15,),
Padding(
padding: const EdgeInsets.only(left: 40,right: 40),
child: Text(yourController.onBoardPages[index].discription,
style: TextStyle(
color: not_sopure_black,
fontSize: getHeight(15),
fontFamily: 'Metropolis-Regular' ,
),
),
),
],
),
),
SizedBox(height: 15,),
Image.asset(yourController.onBoardPages[index].pngimage),
],
),
),
),
),
),
],
),
),
),
bottomNavigationBar: BottomAppBar(
color: Colors.transparent,
elevation: 0,
child: Container(
height: 75,
width: MediaQuery.of(context).size.width,
child: Padding(
padding: const EdgeInsets.only(left: 25,right:25,),
child: Container(
width: MediaQuery.of(context).size.width,
child: Stack(
children: [
Align(
alignment: Alignment.centerLeft,
child: Container(
child: Row(
children: List.generate(yourController.onBoardPages.length,
(index)=>Obx(()=>
AnimatedContainer(
duration: Duration(milliseconds: 200),
margin: EdgeInsets.only(right: 5),
height: 10,
width: yourController.selectedPagexNumber.value == index ? 20 : 10,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(60),
color: yourController.selectedPagexNumber.value == index
? darkish_color
: not_sopure_black,),
),
)),
),
),
),
Align(
alignment: Alignment.centerRight,
child: Container(
width: 130,
height: 52,
child: RaisedButton(
elevation: 0,
onPressed: yourController.forwardAct,
splashColor: not_sopure_black,
color: darkish_color,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100)
),
child: Obx(() =>
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(yourController.isLastPage ? 'Next' : 'Next',
style: TextStyle(
color: Colors.white,
fontFamily: 'Metropolis-Semibold',
fontSize: 16,
),
),
],
),
),
),
),
)
],
),
),
),
),
),
);
}
}