Exit from gridview.builder iteration in flutter or remove empty space - flutter

I am trying to implement a vision board. I'm using gridview.builder for adding up to 12 images. Almost everything works as I expect: adding up to 12 images, but when the limit is reached, somehow I want to stop the iteration, because I am not able to return null, and any widget I return, it will create additional space I don't want.
GridView.builder(
clipBehavior: Clip.none,
physics: ScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: SizeConfig.screenWidth!/3,
crossAxisSpacing: 0,
mainAxisSpacing: 0),
itemCount: visions.length+1,
itemBuilder: (BuildContext ctx, index) {
print("__________");
print("AM INTRAT IN ITEM BUILDER");
print("INDEX $index");
print(visions.length);
if (index < visions.length) {
print("PHOTO ALREADY ADDED CONTAINER");
return Stack(
alignment: Alignment.center,
children: [
Container(
width: double.infinity,
height: double.infinity,
),
Container(
width: SizeConfig.screenWidth!/4,
height: SizeConfig.screenWidth!/4,
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(File(visions[index])),
fit: BoxFit.cover),
borderRadius: const BorderRadius.all(
Radius.circular(
5.0) // <--- border radius here
),
),
),
Positioned(
top:0,
right:0,
child: Container(
child: ClipOval(
child: InkWell(
onTap: () {
_removeVisions(index);
},
child: Container(
padding: const EdgeInsets.all(5),
color: Colors.white,
child:
const Icon(
Icons.delete,
size: 16,
color: Color(0xff221F1E)),
),
),
),
),
),
],
clipBehavior: Clip.none,
);
}
else if(index<12){
print("ADAUGA POZA");
print("INDEX $index");
print(visions.length);
return InkWell(
onTap: () {
_openGallery(context);
},
child:
Stack(
alignment: Alignment.center,
children:[
Container(
width: SizeConfig.screenWidth!/4,
height: SizeConfig.screenWidth!/4,
decoration:
BoxDecoration(
border: Border.all(color: const Color(0xff221F1E)),
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
),
child:
const Icon(
Icons.add,
size: 22,
color: Color(0xff221F1E),
)
),
],
),
);
}
else {
return Container(color: Colors.red);
}
}
),
I want to remove that red container.
I have also tried to hardcode something with Positioned widget, but nothing worked, so I am trying somehow to exit when index is equal to 12 or any other solution...

I would try a true/false statement like this for your itemcount:
itemCount: (visions.length == 12) ? visions.length : visions.length + 1,

Yes, you can't return a null value but you can simply empty the widget. So, what I mean, SizedBox widget. Added an example for you, just check it
GridView.builder(
clipBehavior: Clip.none,
physics: ScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: SizeConfig.screenWidth!/3,
crossAxisSpacing: 0,
mainAxisSpacing: 0),
itemCount: visions.length+1,
itemBuilder: (BuildContext ctx, index) {
print("__________");
print("AM INTRAT IN ITEM BUILDER");
print("INDEX $index");
print(visions.length);
if (index < visions.length) {
print("PHOTO ALREADY ADDED CONTAINER");
return Stack(
alignment: Alignment.center,
children: [
Container(
width: double.infinity,
height: double.infinity,
),
Container(
width: SizeConfig.screenWidth!/4,
height: SizeConfig.screenWidth!/4,
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(File(visions[index])),
fit: BoxFit.cover),
borderRadius: const BorderRadius.all(
Radius.circular(
5.0) // <--- border radius here
),
),
),
Positioned(
top:0,
right:0,
child: Container(
child: ClipOval(
child: InkWell(
onTap: () {
_removeVisions(index);
},
child: Container(
padding: const EdgeInsets.all(5),
color: Colors.white,
child:
const Icon(
Icons.delete,
size: 16,
color: Color(0xff221F1E)),
),
),
),
),
),
],
clipBehavior: Clip.none,
);
}
else if(index<12){
print("ADAUGA POZA");
print("INDEX $index");
print(visions.length);
return InkWell(
onTap: () {
_openGallery(context);
},
child:
Stack(
alignment: Alignment.center,
children:[
Container(
width: SizeConfig.screenWidth!/4,
height: SizeConfig.screenWidth!/4,
decoration:
BoxDecoration(
border: Border.all(color: const Color(0xff221F1E)),
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
),
child:
const Icon(
Icons.add,
size: 22,
color: Color(0xff221F1E),
)
),
],
),
);
}
else {
return const SizedBox.shrink();
}
}
),

Related

how to remove the gridView extra space it give between widgets - Flutter

i am working on this flutter app where i need to show the children in a grid view, so i used a column widget in side GridView.builder like shown below, i want to remove the sapcing where its marked in the red, and leave it to be responsive somehow...
GridView widget:
GridView.builder(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
crossAxisSpacing: 10,
mainAxisSpacing: 10,
maxCrossAxisExtent: 450,
),
primary: false,
shrinkWrap: true,
padding: const EdgeInsets.only(
right: 25,
left: 25,
top: 20,
),
itemCount: data.length,
itemBuilder: (ctx, index) {
return VideoWidget(
oneVideoData: data[index],
);
},
),
VideoWidget:
Container(
color: Colors.red,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: double.infinity,
decoration: BoxDecoration(
...
),
child: Row(
children: [
...
],
),
),
Stack(
alignment: AlignmentDirectional.center,
children: [
_videoPlayerControllerFFrame.value.isInitialized
? AspectRatio(
aspectRatio:
_videoPlayerControllerFFrame.value.aspectRatio,
child: VideoPlayer(
_videoPlayerControllerFFrame,
),
)
: Container(
height: 250,
),
_isVideoLoading
? const CircularProgressIndicator(
color: Colors.yellow,
)
: IconButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return VideoPlayerWidget(
oneVideoData: widget.oneVideoData,
videoController: _videoPlayerController,
);
});
},
icon: Icon(
Icons.play_arrow,
color: Theme.of(context).colorScheme.tertiary,
size: 50,
),
),
],
),
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 10,
),
...
),
),
],
),
);
this a screen shot of the output:
i want to get rid of the red space in the bottom.
Thanks in advance
Try below code hope its help to you.
GridView.builder(
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemCount: 6,
itemBuilder: (BuildContext context, int index) {
return Card(
elevation: 5,
shadowColor: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
10,
),
),
margin: EdgeInsets.all(5),
child: Container(
height: 200,
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: EdgeInsets.all(2),
child: Row(
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.black,
width: 1.0,
),
),
child: CircleAvatar(
radius: 20,
backgroundImage: NetworkImage(
'https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png',
),
),
),
SizedBox(
width: 10,
),
Text('Person ${index.toString()}'),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
'https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png',
),
),
),
),
),
Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.yellow,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(10.0),
),
),
child: Text(
'Awesome Product From Person ${index.toString()}',
),
),
],
),
),
);
},
),
Result Screen->

I am trying to use keys to preserve the state of the widgets and remove the blinking effect when setState is called

I am trying to remove the blinking/flashing effect after the widgets are rebuild. I read about keys, but it's not working, I added a unique key to every GridView builder element as you see in the code below.
Now when I resize, the widgets are rebuilt because the setState function is called but I can not preserve their state.
void addOutfitPlannerDialog(BuildContext context) async{
await showGeneralDialog(
barrierColor: Colors.black.withOpacity(0.5),
transitionBuilder: (context, a1, a2, widget) {
return SafeArea(
child: Transform.scale(
scale: a1.value,
child: Opacity(
opacity: a1.value,
child: AlertDialog(
actionsPadding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
contentPadding: const EdgeInsets.fromLTRB(0, 20, 0, 0),
titlePadding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
buttonPadding: const EdgeInsets.all(0),
title: _getBackAndSaveButtons(context),
backgroundColor: Colors.white,
insetPadding: const EdgeInsets.all(0),
content: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return SizedBox(
width: 100.w,
height: 100.h,
child: Stack(
children: [
Positioned(
top: 0,
child:
Container(
width: 100.w,
height: 82.h,
color: const Color(0xff393432),
child: FittedBox(
fit: BoxFit.fill,
child: Container(
width: 100.w,
height: 100.h,
margin: EdgeInsets.fromLTRB(45, 10, 45, 15.h),
child: Screenshot(
controller: screenshotController,
child: Container(
color: Colors.white,
child: Stack(
children: stackChildren,
),
),
),
),
),
),
),
Positioned(
bottom: 0,
child: Container(
height: heightBottomOutfitPlanner,
decoration: const BoxDecoration(
color: Colors.white,
border: Border(
top: BorderSide( // <--- top side
color: Colors.grey,
width: 1.0,
),
),
),
width: 100.w,
child: Column(
children: [
SizedBox(
width: 100.w,
height: 8.h,
child: Row(
children: [
Expanded(
flex: 7,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: outfitPlanerOrganizerEntriesList
.length,
itemBuilder: (BuildContext context,
int index) {
return InkWell(
onTap: () {
getOutfitPlannerTabTappedImages(
outfitPlanerOrganizerEntriesList[index],
setState);
},
child: Container(
padding: const EdgeInsets.fromLTRB(
30, 0, 30, 0),
decoration: (outfitPlanerOrganizerEntriesList[index] ==
myOutfitPlannerTabTappedImages[0]
.closetOrganizer) ||
(outfitPlanerOrganizerEntriesList[index] ==
"To Buy" &&
myOutfitPlannerTabTappedImages[0]
.closetOrganizer ==
null)
? const BoxDecoration(
border: Border(
bottom: BorderSide( // <--- top side
color: Color(0xffE4BCB4),
width: 3.0,
),
),
)
: null,
child: Center(child: Text(
outfitPlanerOrganizerEntriesList[index],
style: TextStyle(
fontSize: SizerUtil
.deviceType ==
DeviceType.mobile
? 16
: 25,
))),
),
);
}
),
),
const SizedBox(width: 30),
Expanded(
flex: 1,
child: Container(
decoration: const BoxDecoration(
border: Border(
left: BorderSide( // <--- top side
color: Colors.black,
width: 1.0,
),
),
),
child: GestureDetector(
onPanStart: (details) =>
_handleDrag(details, setState),
onPanUpdate: (details) =>
_handleUpdate(details, setState),
child: Icon(Icons.drag_indicator,
size: SizerUtil.deviceType ==
DeviceType.mobile ? 35 : 45,
),
)
),
),
],
),
),
const SizedBox(height: 5),
!isLoadingOutfitPlannerTabTappedImages ? Container(
width: 100.w,
margin: const EdgeInsets.fromLTRB(5, 0, 5, 0),
height: heightBottomOutfitPlanner - 10.h,
child: GridView.builder(
physics: const ScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
crossAxisSpacing: 5,
mainAxisSpacing: 5,
maxCrossAxisExtent: SizeConfig.screenWidth! /
4,),
itemCount: myOutfitPlannerTabTappedImages
.length,
itemBuilder: (BuildContext ctx, index) {
return InkWell(
key: Key(index.toString()),
onTap: () {
try {
removeBackground(ctx, setState, CleverCloset.dataFromBase64String(myOutfitPlannerTabTappedImages[index].getImage!));
}
catch (e) {
stackChildren.add(MoveableStackItem(CleverCloset.imageFromBase64String(myOutfitPlannerTabTappedImages[index].getImage!).image));
}
},
child: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(20))
),
width: SizeConfig.screenWidth! / 4,
height: SizeConfig.screenWidth! / 4,
child: FittedBox(
child:
FadeInImage(
placeholder: const AssetImage(
'assets/placeholder.gif'),
image: CleverCloset
.imageFromBase64String(
myOutfitPlannerTabTappedImages[index]
.getImage!)
.image,
fit: BoxFit.fill,
),
fit: BoxFit.fill,
),
),
);
}
),
) : Container(),
],
),
),
),
],
),
);
}
)
),
),
),
);
},
transitionDuration: const Duration(milliseconds: 100),
barrierDismissible: false,
barrierLabel: '',
context: context,
pageBuilder: (context, animation1, animation2) {return Container();}
);
}
You can add the below logic to your code. It basically gets executed when the widget has build.
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) => function(context));
}
And now you can implement the function(context) to do what you need to do after the build.

How to stop GridView Builder refreshing the widget in Flutter

I am trying to get rid of this blinking/flashing of the widget presented in the image below. This is an Alert Dialog opened. Below it's a GridView Builder which creates images. The images are refreshing when I am trying to drag and resize the height of the container. I know setState it's called multiple times, but it doesn't matter, the widget should be immutable.
I changed the Grid View to a Stateless Widget, after trying a while using AutomaticKeepAliveClientMixin, wantToKeepAlive, but nothing is changing.
class GridViewBuilderOutiftTabTapped extends StatelessWidget {
final List<CleverCloset> myClassVar;
const GridViewBuilderOutiftTabTapped(this.myClassVar);
#override
Widget build(BuildContext context) {
return GridView.builder(
physics: const ScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
crossAxisSpacing: 5,
mainAxisSpacing: 5,
maxCrossAxisExtent: SizeConfig.screenWidth!/4,),
itemCount: myClassVar.length,
itemBuilder: (BuildContext ctx, index) {
return InkWell(
onTap: (){
},
child: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20))
),
width: SizeConfig.screenWidth!/4,
height: SizeConfig.screenWidth!/4,
child: FittedBox(
child:
FadeInImage(
placeholder: const AssetImage('assets/placeholder.gif'),
image: CleverCloset.imageFromBase64String(myClassVar[index].getImage!).image,
fit: BoxFit.fill,
),
fit: BoxFit.fill,
),
),
);
}
);
}
}
void addOutfitPlannerDialog(BuildContext context) async{
await showGeneralDialog(
barrierColor: Colors.black.withOpacity(0.5),
transitionBuilder: (context, a1, a2, widget) {
return SafeArea(
child: Transform.scale(
scale: a1.value,
child: Opacity(
opacity: a1.value,
child: AlertDialog(
actionsPadding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
contentPadding: const EdgeInsets.fromLTRB(0, 20, 0, 0),
titlePadding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
buttonPadding: const EdgeInsets.all(0),
title: _getBackAndSaveButtons(context),
backgroundColor: Colors.white,
insetPadding: const EdgeInsets.all(0),
content: SizedBox(
width: 100.w,
height: 100.h,
child: Stack(
children: [
Positioned(
top: 0,
child: Container(
width: SizeConfig.screenWidth,
height: 82.h,
color: const Color(0xff393432),
child: Container(
margin: EdgeInsets.fromLTRB(45, 8, 45, 10.h),
color: Colors.white,
),
),
),
Positioned(
bottom: 0,
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Container(
height: heightBottomOutfitPlanner,
decoration: const BoxDecoration(
color: Colors.white,
border: Border(
top: BorderSide( // <--- top side
color: Colors.grey,
width: 1.0,
),
),
),
width: 100.w,
child: Column(
children: [
SizedBox(
width: 100.w,
height: 8.h,
child: Row(
children: [
Expanded(
flex:7,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: outfitPlanerOrganizerEntriesList.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: (){
getOutfitPlannerTabTappedImages(outfitPlanerOrganizerEntriesList[index], setState);
},
child: Container(
padding: const EdgeInsets.fromLTRB(30, 0, 30, 0),
decoration: (outfitPlanerOrganizerEntriesList[index]==myOutfitPlannerTabTappedImages[0].closetOrganizer) || (outfitPlanerOrganizerEntriesList[index]=="To Buy" && myOutfitPlannerTabTappedImages[0].closetOrganizer==null) ? const BoxDecoration(
border: Border(
bottom: BorderSide( // <--- top side
color: Color(0xffE4BCB4),
width: 3.0,
),
),
):null,
child: Center(child: Text(outfitPlanerOrganizerEntriesList[index],
style: const TextStyle(
fontSize: 16,
))),
),
);
}
),
),
const SizedBox(width: 30),
Expanded(
flex:1,
child: Container(
decoration: const BoxDecoration(
border: Border(
left: BorderSide( // <--- top side
color: Colors.black,
width: 1.0,
),
),
),
child: GestureDetector(
onPanStart:(details) => _handleDrag(details, setState),
onPanUpdate:(details) => _handleUpdate(details, setState),
child: const Icon(Icons.drag_indicator,
size: 35,
),
)
),
),
],
),
),
const SizedBox(height: 5),
!isLoadingOutfitPlannerTabTappedImages ? Container(
width: 100.w,
margin: const EdgeInsets.fromLTRB(5, 0, 5, 0),
height: heightBottomOutfitPlanner-10.h,
child: GridViewBuilderOutiftTabTapped(myOutfitPlannerTabTappedImages),
) : Container(),
],
),
);
},
),
)
],
),
)
),
),
),
);
},
transitionDuration: const Duration(milliseconds: 100),
barrierDismissible: true,
barrierLabel: '',
context: context,
pageBuilder: (context, animation1, animation2) {return Container();}
);
}

Flutter can't align widget above another widget even when using the stack widget?

I'm trying to align the dog image circle widget above the white card I'm using stack and align but it's not working I also tried padding
You can see here it's not going above the white card the idea is the circle will be above the card halfway
Like the following
Here is my code
if (snapshot.hasData && !snapshot.hasError) {
return SizedBox(
height: 375,
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
padding: const EdgeInsets.symmetric(vertical: 5.0),
itemCount: snapshot.docs.length,
itemBuilder: (context, index) {
return Column(
children: <Widget>[
SizedBox(
// you may want to use an aspect ratio here for tablet support
height: 200.0,
width: MediaQuery.of(context).size.width,
child: PageView.builder(
itemCount: snapshot.docs.length,
// store this controller in a State to save the carousel scroll position
controller: PageController(
viewportFraction: 0.6,
),
onPageChanged: (page) {
setState(() {
selectedDog = page;
});
},
itemBuilder: (context, itemIndex) {
return Stack(
children: [
DogCarouselCard(
snapshotData: snapshot.docs[itemIndex].data(),
),
Align(
alignment: Alignment.topCenter,
child: SizedBox(
height: 50,
width: 50,
child: snapshot.docs[itemIndex]
.data()
.dogImage ==
null
? Image.asset(
'assets/images/placeholder.png',
)
: CachedNetworkImage(
width: 50,
height: 50,
imageUrl: snapshot.docs[itemIndex]
.data()
.dogImage
.toString(),
imageBuilder: (
context,
imageProvider,
) =>
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
border: Border.all(
color: accentColor,
width: 2,
),
boxShadow: [
BoxShadow(
color: Colors.black87
.withOpacity(0.6),
spreadRadius: 0.8,
blurRadius: 2,
offset: const Offset(
1,
1,
), // changes position of shadow
),
],
),
),
placeholder: (context, url) =>
const CircularProgressIndicator(
color: primaryColor,
),
errorWidget: (context, url, error) =>
const Icon(Icons.error),
),
),
),
],
);
},
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: PageViewDotIndicator(
currentItem: selectedDog,
count: snapshot.docs.length,
unselectedColor: Colors.white,
selectedColor: accentColor,
duration: const Duration(milliseconds: 200),
padding: EdgeInsets.zero,
fadeEdges: false,
),
),
),
],
);
},
),
);
}
I got it working but doing the following
Adding Positioned widget
return Stack(
clipBehavior: Clip.none,
alignment: Alignment.topCenter,
children: [
DogCarouselCard(
snapshotData: snapshot.docs[itemIndex].data(),
),
Positioned(
top: 0,
child: snapshot.docs[itemIndex]
.data()
.dogImage ==
null
? Image.asset(
'assets/images/placeholder.png',
)
: CachedNetworkImage(
width: 50,
height: 50,
imageUrl: snapshot.docs[itemIndex]
.data()
.dogImage
.toString(),
imageBuilder: (
context,
imageProvider,
) =>
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
border: Border.all(
color: whiteColor, //accentColor,
width: 2,
),
/*
boxShadow: [
BoxShadow(
color: Colors.black87
.withOpacity(0.6),
spreadRadius: 0.8,
blurRadius: 2,
offset: const Offset(
1,
1,
), // changes position of shadow
),
],
*/
),
),
placeholder: (context, url) =>
const CircularProgressIndicator(
color: primaryColor,
),
errorWidget: (context, url, error) =>
const Icon(Icons.error),
),
),
],
);

Rounded ends on horizontal listview flutter

do you know if there is any way i could make my listview ends rounded?
Ive tried wraping the listview builder in a container with box decoration, borderadius and it did not work.
Any help is appreciated.
How it looks like:
https://i.stack.imgur.com/Jr4WJ.png
my code:
Padding(
padding: EdgeInsets.only(left: 5.0),
child: Container(
color: null,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: profiles[0].skills.length,
itemBuilder: (BuildContext context, int index) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15)),
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
setState(() {
_filterselectedIndex = index;
});
print(index);
} //setState(() => _filterselected = index)
,
child: Align(
alignment: Alignment.centerRight,
child: Container(
margin: EdgeInsets.all(10.0),
height: 32,
//width: 100,
decoration: BoxDecoration(
color: _filterselectedIndex == index
? Theme.of(context).accentColor
: Colors.white,
borderRadius:
BorderRadius.circular(15.0),
),
child: Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
),
child: Align(
alignment: Alignment.center,
child: Text(
profiles[0].skills[index],
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w600,
),
),
),
),
),
),
),
);
},
),
))
Yes, there are multiple ways. The easiest way i think would be using containers. Wrap your widget with a container widget. Then add decoration to it like the code below :
return ListView.builder(
itemBuilder: (context, position) {
return Container(
decoration: BoxDecoration(
color: Colors.black,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25.0),
bottomRight: Radius.circular(25.0))),
child: Paste your existing code.
))
You can also do it using ClipRRect.
If I am correctly understanding your question you want to want to round the corner of yours listView, SO there are various method of doing that, One method is Wrapping the Listview in Container and then in decoration giving it borderRadous.
I have implemented the same functionality for you.
here is the code.
return Scaffold(
appBar: AppBar(
title: Text("App Bar"),
),
body: Container(
padding: EdgeInsets.all(26),
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(
16) // <- incease the value for more rounded corner
),
child: ListView(
children: <Widget>[
Text("List Item 1"),
Divider(),
Text("List Item 1"),
Divider(),
Text("List Item 1"),
Divider(),
Text("List Item 1"),
Divider(),
],
),
),
);
I have a clone of app where I have implemented this type of listview with greater functionality like gestures and divider and other. (https://github.com/atul-chaudhary/country_dairy/blob/master/lib/user_func/user_menu.dart)
There are two ways of doing this,
First is using Container and second is ClipRRect
*Note: If you will use Container the widgets inside it will flow out if your BorderRadius will be a large number. But in ClipRRect this will not happen, it will stay inside.
See the code:
Using Container
Container(
height: 200.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(50.0))
),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.blue,
width: 150.0,
),
);
},
itemCount: 10
),
),
Using ClipRRect
SizedBox(
height: 200.0,
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(50.0)),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.blue,
width: 150.0,
),
);
},
itemCount: 10
),
),
)