Horizontal viewport was given unbounded height - Flutter - flutter

I'm a newbie in App development and encountering an error while rendering the Horizontal Card scroll.
howItWorks.dart
class HowItWorksCards extends StatefulWidget {
HowItWorksCards();
#override
_HowItWorksCardsState createState() => _HowItWorksCardsState();
}
class _HowItWorksCardsState extends State<HowItWorksCards> {
int _currentPage = 0;
PageController _pageController = PageController(viewportFraction: 0.8, keepPage: true);
List<Widget> _pages = [
SliderPage(
index: 1,
title: "Title1",
info:"Summary",
image: "assets/images/howItWorks/1.png"),
SliderPage(
index: 1,
title: "Title1",
info:"Summary",
image: "assets/images/howItWorks/1.png"),
SliderPage(
index: 1,
title: "Title1",
info:"Summary",
image: "assets/images/howItWorks/1.png"),
];
_onchanged(int index) {
setState(() {
_currentPage = index;
});
}
#override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
flex: 5,
child: PageView.builder( // this throws the exception.
controller: _pageController,
// physics: BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
itemCount: _pages.length,
onPageChanged: _onchanged,
itemBuilder: (context, int index) {
return _pages[index];
},
),
),
Flexible( // this works absolutely fine when the above Flexible widget is commented.
flex: 4,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: List<Widget>.generate(
_pages.length,
(int index) {
return AnimatedContainer(
duration: Duration(milliseconds: 300),
height: 5,
width: (index == _currentPage) ? 30 : 10,
margin: EdgeInsets.symmetric(horizontal: 5, vertical: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: (index == _currentPage)
? AppTheme.globalTheme.primaryColor
: AppTheme.globalTheme.primaryColor
.withOpacity(0.5)));
},
)),
),
],
);
}
}
slider.dart
class SliderPage extends StatelessWidget {
final String image;
final int index;
final String title;
final String info;
SliderPage(
{#required this.image,
#required this.info,
#required this.title,
#required this.index});
#override
Widget build(BuildContext context) {
return Card(
elevation: 20,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.all(5.0),
height: 175,
child: Image.asset(
image,
fit: BoxFit.fitHeight,
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(left: 5),
child: Text(this.title,
style: getFontStyle(
bold: true,
color: Color(0xFF3C3C43),
fontSize: 18,
fontStyle: FontStyles.SFProDisplay),
textAlign: TextAlign.center),
),
],
),
),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5),
child: Text(
this.info,
style: getFontStyle(
color: Color(0xFF3C3C43),
fontSize: 16,
fontStyle: FontStyles.SFProDisplay),
textAlign: TextAlign.center,
),
),
]),
);
}
}
main.dart
void main() => runApp(MaterialApp(home: AmazonOrdersInvoiceOnboarding()));
class AmazonOrdersInvoiceOnboarding extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: GoBackAppBar(
customBackGroundColor: Color(0x1affb500),
title: "",
),
body: ListView(
shrinkWrap: true,
children: [
HowItWorksCards(),
],
),
);
}
}
I'm getting some exceptions.
Horizontal viewport was given unbounded height. - Have already used Flexible. Not sure why I'm still getting this exception.
RenderBox was not laid out: RenderViewport#c29be NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I found a lot of related questions on SO, but to no avail.

This error happen when we use infinite sized widget inside one-another,
here you are using Column inside ListView, both take infinite height, if you wrap Column fixed sized widget it will solve the problem,
And I strongly suggest you to watch this video by flutter
https://www.youtube.com/watch?v=jckqXR5CrPI
on howItWorks.dart
#override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
flex: 5,
child: Container(
height: 250,
child: PageView.builder(
// this throws the exception.
controller: _pageController,
// physics: BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
itemCount: _pages.length,
onPageChanged: _onchanged,
itemBuilder: (context, int index) {
return _pages[index];
},
),
),
),
Flexible(
// this works absolutely fine when the above Flexible widget is commented.
flex: 4,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: List<Widget>.generate(
_pages.length,
(int index) {
return AnimatedContainer(
duration: Duration(milliseconds: 300),
height: 5,
width: (index == _currentPage) ? 30 : 10,
margin: EdgeInsets.symmetric(horizontal: 5, vertical: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.amber)
// (index == _currentPage)
// ? AppTheme.globalTheme.primaryColor
// : AppTheme.globalTheme.primaryColor
// .withOpacity(0.5))
);
},
)),
),
],
);
}

Related

Flutter : Horizontally and Vertically Scrolling Time Table with two sided header

In my flutter application I want to create a timetable widget as below which will scroll horizontally and vertically with corresponding heading. The timetable should have 'Day' as horizontal heading and 'Period' as vertical heading. During horizontal scrolling the 'Period' header should freeze and horizontal 'Day' header should scroll with data. Similarly, during vertical scrolling the 'Day' header should freeze and vertical 'Period' header should scroll with data. How can I achieve a widget like that.Please help..
In Android we can obtain the above type of scrolling by extending HorizontalScrollView & VerticalScrollView.
You can archive this using nested listView widgets.
You can try this approach:
class TimeTableView extends StatefulWidget {
const TimeTableView({super.key});
#override
State<TimeTableView> createState() => _TimeTableViewState();
}
class _TimeTableViewState extends State<TimeTableView> {
final periodsSlots = 15;
final double containerHeight = 55.0;
final double containerWidth = 80;
final days = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
final subjects = [
"Maths",
"Hindi",
"English",
"Chemistry",
"History",
"Geography",
];
late ScrollController mainController;
late ScrollController secondController;
#override
void initState() {
super.initState();
secondController = ScrollController();
mainController = ScrollController()
..addListener(() {
if (mainController.hasClients && secondController.hasClients) {
secondController.jumpTo(mainController.offset);
}
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Time Table"),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: PageView(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
// Top header View
SizedBox(
height: containerHeight,
width: containerWidth,
child: CustomPaint(
painter: RectanglePainter(),
child: Stack(
children: const [
Align(
alignment: Alignment.topRight,
child: Padding(
padding: EdgeInsets.all(4.0),
child: Text("Day"),
),
),
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: EdgeInsets.all(4.0),
child: Text("Period"),
),
),
],
),
),
),
Expanded(
child: SizedBox(
height: containerHeight,
child: SingleChildScrollView(
physics: const ClampingScrollPhysics(),
padding: EdgeInsets.zero,
scrollDirection: Axis.horizontal,
controller: mainController,
child: Row(
children: List<Widget>.generate(
days.length,
(index) => Container(
height: containerHeight,
width: containerWidth,
color: bgColorHeader(index),
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8),
child: Center(child: Text(days[index])),
),
),
),
),
),
),
)
],
),
SizedBox(
// Added fixed size to scroll listView horizontal
height: 500,
child: ListView.builder(
physics: const ClampingScrollPhysics(),
padding:
EdgeInsets.zero, // remove listview default padding.
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: periodsSlots,
itemBuilder: (context, index) => Container(
height: containerHeight,
width: containerWidth,
color: bgColorHeader(index),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
// period header
Padding(
padding: EdgeInsets.zero,
child: SizedBox(
width: containerWidth,
height: containerHeight,
child: Center(child: Text("period ${index + 1}")),
),
),
// period subjects
Expanded(
child: SizedBox(
height: containerHeight,
child: SingleChildScrollView(
physics: const ClampingScrollPhysics(),
padding: EdgeInsets.zero,
scrollDirection: Axis.horizontal,
controller: secondController,
child: Row(
children: List<Widget>.generate(
subjects.length,
(index) => Container(
color: Colors.white,
child: Container(
height: containerHeight,
width: containerWidth,
color: bgColorSubject(index),
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4),
child: Text(subjects[index]),
)),
),
),
),
),
),
),
)
],
),
),
),
)
],
),
],
),
),
);
}
// Alternate background colors
Color bgColorHeader(int index) =>
index % 2 == 0 ? Colors.cyan.withOpacity(0.5) : Colors.cyanAccent;
Color bgColorSubject(int index) =>
index % 2 == 0 ? Colors.grey.withOpacity(0.5) : Colors.grey;
}
// Draw cross line from top left container
class RectanglePainter extends CustomPainter {
#override
void paint(Canvas canvas, Size size) {
final backgroundPaint = Paint()
..color = Colors.cyanAccent
..strokeWidth = 2.0
..strokeCap = StrokeCap.round;
final crossLine = Paint()
..color = Colors.white
..strokeWidth = 2.0
..strokeCap = StrokeCap.round;
// Draw the rectangle
canvas.drawRect(Offset.zero & size, backgroundPaint);
// Draw the cross line
canvas.drawLine(Offset.zero, Offset(size.width, size.height), crossLine);
//canvas.drawLine(Offset(0, size.height), Offset(size.width, 0), crossLine);
}
#override
bool shouldRepaint(RectanglePainter oldDelegate) => false;
}
Scrolling widgets will create a default scroll controller (ScrollController class) if none is provided. A scroll controller creates a ScrollPosition to manage the state specific to an individual Scrollable widget.
To link our scroll controllers we’ll use linked_scroll_controller, a scroll controller that allows two or more scroll views to be in sync.
import 'package:flutter/material.dart';
import 'package:linked_scroll_controller/linked_scroll_controller.dart';
class ScrollDemo extends StatefulWidget {
#override
_ScrollDemoState createState() => _ScrollDemoState();
}
class _ScrollDemoState extends State<ScrollDemo> {
final List<String> colEntries = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('');
final List<String> rowEntries =
Iterable<int>.generate(15).map((e) => e.toString()).toList();
late LinkedScrollControllerGroup _horizontalControllersGroup;
late ScrollController _horizontalController1;
late ScrollController _horizontalController2;
late LinkedScrollControllerGroup _verticalControllersGroup;
late ScrollController _verticalController1;
late ScrollController _verticalController2;
#override
void initState() {
super.initState();
_horizontalControllersGroup = LinkedScrollControllerGroup();
_horizontalController1 = _horizontalControllersGroup.addAndGet();
_horizontalController2 = _horizontalControllersGroup.addAndGet();
_verticalControllersGroup = LinkedScrollControllerGroup();
_verticalController1 = _verticalControllersGroup.addAndGet();
_verticalController2 = _verticalControllersGroup.addAndGet();
}
#override
void dispose() {
_horizontalController1.dispose();
_horizontalController2.dispose();
_verticalController1.dispose();
_verticalController2.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('sync scroll demo'),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 75,
height: 75,
color: Colors.grey[200],
),
const SizedBox(width: 10),
Container(
height: 75,
width: 400,
color: Colors.blue[100],
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
controller: _horizontalController2,
child: HeaderContainer(rowEntries: rowEntries),
),
)
],
),
const SizedBox(height: 10),
Row(
children: <Widget>[
Container(
width: 75,
height: 400,
color: Colors.blue[100],
child: SingleChildScrollView(
controller: _verticalController2,
child: ColumnContainer(
colEntries: colEntries,
),
),
),
const SizedBox(width: 10),
SizedBox(
width: 400,
height: 400,
child: SingleChildScrollView(
controller: _verticalController1,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
controller: _horizontalController1,
child: BodyContainer(
rowEntries: rowEntries,
colEntries: colEntries,
),
),
),
)
],
),
],
),
),
),
);
}
}
class ColumnContainer extends StatelessWidget {
final List<String> colEntries;
const ColumnContainer({
Key? key,
required this.colEntries,
}) : super(key: key);
#override
Widget build(BuildContext context) {
int numberOfRows = colEntries.length;
return Column(
children: List.generate(
numberOfRows,
(i) {
return Container(
height: 75,
width: 75,
decoration: BoxDecoration(border: Border.all(color: Colors.white)),
child: Center(child: Text(colEntries[i])),
);
},
),
);
}
}
class HeaderContainer extends StatelessWidget {
final List<String> rowEntries;
const HeaderContainer({
Key? key,
required this.rowEntries,
}) : super(key: key);
#override
Widget build(BuildContext context) {
int _numberOfColumns = rowEntries.length;
return Row(
children: List.generate(
_numberOfColumns,
(i) {
return Container(
height: 75,
width: 75,
decoration: BoxDecoration(border: Border.all(color: Colors.white)),
child: Center(child: Text(rowEntries[i])),
);
},
),
);
}
}
class BodyContainer extends StatelessWidget {
final List<String> colEntries;
final List<String> rowEntries;
const BodyContainer({
Key? key,
required this.colEntries,
required this.rowEntries,
}) : super(key: key);
#override
Widget build(BuildContext context) {
int _numberOfColumns = rowEntries.length;
int _numberOfLines = colEntries.length;
return Column(
children: List.generate(_numberOfLines, (y) {
return Row(
children: List.generate(_numberOfColumns, (x) {
return TableCell(item: "${colEntries[y]}${rowEntries[x]}");
}),
);
}),
);
}
}
class TableCell extends StatelessWidget {
final String item;
const TableCell({
Key? key,
required this.item,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
height: 75,
width: 75,
decoration: BoxDecoration(border: Border.all(color: Colors.grey)),
child: Center(child: Text(item)),
);
}
}
I found these solutions from these 2 links.
Flutter: How to create linked scroll widgets
Flutter: Creating a two-direction scrolling table with a fixed head and column

GridView height fit the children height flutter

I'm confuse about the usage of gridview in flutter.
I want to display a list of features with their rates.
The feature component/widget isn't that big in term of height but when I place them in a gridview the height of each case is way more bigger that it needs to be.
How can I control the height of each case to fit the child height ?
here is my code :
import 'package:flutter/material.dart';
import 'package:project/Components/ReviewComps/AttributeRatings.dart';
class ReviewPage extends StatelessWidget {
const ReviewPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: const <Widget>[
AttributeRatings(),
],
),
),
));
}
}
here is my gridview that create problems :
import 'package:flutter/material.dart';
class AttributeRatings extends StatelessWidget {
const AttributeRatings({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
var featureList = [
_featureItems(4),
_featureItems(3.2),
_featureItems(1),
];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text("Features average rating"),
GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 20,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: featureList,
),
],
);
}
}
Container _featureItems(double rate) {
return Container(
color: Colors.red,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Feature'),
Text(rate.toString()),
],
),
Stack(
children: [
Container(
height: 2,
width: double.infinity,
color: const Color(0xffDBDFED),
),
FractionallySizedBox(
widthFactor: rate / 5,
child: Container(
height: 2,
color: const Color(0xff39B0EA),
),
)
],
)
],
),
);
}
You can give childAspectRatio to customise a height as following
import 'package:flutter/material.dart';
class AttributeRatings extends StatelessWidget {
const AttributeRatings({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
var featureList = [
_featureItems(4),
_featureItems(3.2),
_featureItems(1),
];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text("Features average rating"),
GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 20,
childAspectRatio: 4,//You may have to calculate based on screen size
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: featureList,
),
],
);
}
}
Container _featureItems(double rate) {
return Container(
color: Colors.red,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Feature'),
Text(rate.toString()),
],
),
Stack(
children: [
Container(
height: 2,
width: double.infinity,
color: const Color(0xffDBDFED),
),
FractionallySizedBox(
widthFactor: rate / 5,
child: Container(
height: 2,
color: const Color(0xff39B0EA),
),
)
],
)
],
),
);
}
The solution I found is quite complicated but I changed the gridview to a list view and put rows inside. The most dificult was to work with odd lengths lists here is my solution :
import 'package:flutter/material.dart';
class AttributeRatings extends StatelessWidget {
const AttributeRatings({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
var featureList = [4, 3.2, 4, 2, 3.2];
double nbRows = featureList.length % 2 == 0
? (featureList.length / 2)
: (featureList.length / 2) + 1;
var reworkedFeatureList = [];
if (featureList.length % 2 == 0) {
for (var i = 0; i < (featureList.length - 1) / 2; i++) {
reworkedFeatureList.add([featureList[i * 2], featureList[(i * 2) + 1]]);
}
} else {
final retVal = featureList.removeLast();
for (var i = 0; i < (featureList.length - 1) / 2; i++) {
reworkedFeatureList.add([featureList[i * 2], featureList[(i * 2) + 1]]);
}
reworkedFeatureList.add([retVal, -1]);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text("Features average rating"),
ListView.separated(
separatorBuilder: (context, index) {
return const SizedBox(height: 12);
},
itemCount: nbRows.toInt(),
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) =>
_featureItemsRow(reworkedFeatureList[index]),
),
],
);
}
}
Row _featureItemsRow(var rates) {
return Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.only(right: 10.0),
child: _featureItem(rates[0].toDouble()),
)),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 10.0),
child: _featureItem(rates[1].toDouble()),
)),
],
);
}
Column _featureItem(double rate) {
if (rate == -1) {
return Column();
} else {
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Feature'),
Text(rate.toString()),
],
),
Stack(
children: [
Container(
height: 2,
width: double.infinity,
color: const Color(0xffDBDFED),
),
FractionallySizedBox(
widthFactor: rate / 5,
child: Container(
height: 2,
color: const Color(0xff39B0EA),
),
)
],
)
],
);
}
}

Place an arrow at the end of the horizontal listview flutter

Place an arrow at the end of the horizontal listview , i tried to warp horizontal listview and sizedbox for the arrow in Raw Widget but the arrow is always shown i wanna show when get the end of the list like this
Row(
children: [
const SizedBox(
width: 100,
height: 375,
child: Icon(
Icons.swipe_left_alt_rounded,
color: Colors.black,
size: 24,
)),
SizedBox(
height: 375,
width: SizeConfig.screenWidth * 0.8,
child: ListView.builder(
reverse: true,
scrollDirection: Axis.horizontal,
You can use itemBuilder to build items based on your need.
class AF extends StatelessWidget {
const AF({super.key});
#override
Widget build(BuildContext context) {
const itemLength = 4;
return Scaffold(
body: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: itemLength,
itemBuilder: (context, index) {
if (index == itemLength - 1) { // here will be the logic
return Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.arrow_back),
itemBuilder(index),
],
);
}
return itemBuilder(index);
},
),
);
}
Widget itemBuilder(int index) =>
Container(width: 200, child: Text("ItemNumber $index"));
}
Try use ListView swap outside Arrow Icon and ListView.builder:
This is demo code:
class TestScreen extends StatelessWidget {
const TestScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SizedBox(
height: 350,
child: ListView(
reverse: true,
scrollDirection: Axis.horizontal,
children: [
ListView.builder(
shrinkWrap: true,
reverse: true,
scrollDirection: Axis.horizontal,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Container(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(border: Border.all(width: 2)),
child: Padding(
padding: const EdgeInsets.all(30),
child: Center(
child: Text(
index.toString(),
),
),
),
);
},
itemCount: 10,
),
const SizedBox(
width: 100,
child: Icon(
Icons.swipe_left_alt_rounded,
color: Colors.black,
size: 24,
)),
],
),
),
);
}
}

Flutter Renderflex Puzzle

I've been trying to solve this for 2 days. I think I've tried every combo, and read through 100 tutorials on here. No matter what I do, I keep getting the same error. One of my columns keeps overflowing. I've marked it with a comment.
The problematic column is inside of AlignedGridView, which is gridview builder like listview. Since this doesn't have a defined height, it keeps throwing the error. I've tried wrapping it in an expanded widget, but that doesn't work.
I'm trying not to define a height because it makes the design look ugly.
If there are any Flutter layout wizards out there who can help, I'm all ears!
Chris
class SoundscapesGrid extends StatefulWidget {
const SoundscapesGrid({
Key? key,
this.width,
this.height,
this.soundscapesList,
}) : super(key: key);
final double? width;
final double? height;
final List<SoundscapesRecord>? soundscapesList;
#override
_SoundscapesGridState createState() => _SoundscapesGridState();
}
class _SoundscapesGridState extends State<SoundscapesGrid> {
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (responsiveVisibility(
context: context,
phone: false,
))
Expanded(
flex: 1,
child: Container(
width: 100,
decoration: BoxDecoration(),
),
),
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(0, 0, 0, 30),
child: AlignedGridView.count(
crossAxisCount: 2,
mainAxisSpacing: 50,
crossAxisSpacing: 20,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: widget.soundscapesList!.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SoundscapePageWidget(
soundscapeImageUrl: widget
.soundscapesList![index].soundscapeImageUrl,
soundscapeName: widget
.soundscapesList![index].soundscapeName,
soundscapeDescription: widget
.soundscapesList![index]
.soundscapeDescription,
soundscapeUid:
widget.soundscapesList![index].uid,
),
),
);
},
/*THIS IS WHERE IT'S OVERFLOWING*/ child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(
0, 0, 0, 5),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.network(
widget.soundscapesList![index]
.soundscapeImageUrl!,
width:
MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
),
),
),
],
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(
0, 10, 0, 5),
child: Text(
widget.soundscapesList![index]
.soundscapeName!,
style: FlutterFlowTheme.of(context)
.title3),
),
),
],
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Text(
widget.soundscapesList![index]
.soundscapeDescription!,
style: FlutterFlowTheme.of(context)
.bodyText2),
),
],
),
],
),
);
},
),
),
),
if (responsiveVisibility(
context: context,
phone: false,
))
Expanded(
flex: 1,
child: Container(
width: 100,
decoration: BoxDecoration(),
),
),
],
),
const SizedBox(height: 20),
],
),
);
}
}

How to add a grid to Cupertino Segmented Control in Flutter

I was referring to this link on Git Hub and I'm trying to add a grid to the segment.
My objective is to add images in a grid view to a segment in Cupertino Segmented Control
return Scaffold(
appBar: CupertinoNavigationBar(
middle: Text("awrdfsfsdfs"),
automaticallyImplyLeading: true,
transitionBetweenRoutes: true,
previousPageTitle: AppLocalizations.of(context).tr('alerts.back'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: ListView(
shrinkWrap: true,
scrollDirection: Axis.vertical,
padding: EdgeInsets.only(top: 20),
children: <Widget>[
CupertinoSegmentedControl(
children: {
0: Text(AppLocalizations.of(context).tr('titles.secImg')),
1: Text(AppLocalizations.of(context).tr('titles.secQuest')),
},
groupValue: _selectedIndexValue,
onValueChanged: (value) {
setState(() => _selectedIndexValue = value);
},
),
_selectedIndexValue == 0 ? IosFirstPage() : IosSecondPage()
],
),
)
],
),
);
}
}
class IosFirstPage extends StatelessWidget {
const IosFirstPage({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
var imgList = [ ];
return Flex(
direction: Axis.vertical,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10,left: 10),
child: Row(
children: <Widget>[
Text(AppLocalizations.of(context).tr('titles.selectSecImg'),style: textTheme.subtitle,textAlign: TextAlign.left,textScaleFactor: 1.2,),
],
)
),
Container(
width: MediaQuery
.of(context)
.size
.width,
height: MediaQuery.of(context).size.height*0.64, //adjust this resize the scroll view of the images
margin: EdgeInsets.only(top: 10,left: 10,right: 10),
color: Colors.white30,
child: GridView.builder(
itemCount: imgList.length,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5),
itemBuilder: (BuildContext context, int index) {
return new GestureDetector(
child: new Card(
elevation: 1.0,
child: new Container(
alignment: Alignment.center,
margin: new EdgeInsets.only(
top: 10.0, bottom: 10.0),
child: new Image.asset(imgList[index], scale: 0.5,)
),
),
onTap: () {
print(index);
/*showDialog(
barrierDismissible: false,
context: context,
child: new CupertinoAlertDialog(
title: new Column(
children: <Widget>[
new Text("GridView"),
new Icon(
Icons.favorite,
color: Colors.red,
),
],
),
content: new Text( imgList[index]),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("OK"))
],
));*/
},
);
},
),
),
],
);
}
}
class IosSecondPage extends StatelessWidget {
const IosSecondPage({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container();.
}
}