Rounded ends on horizontal listview flutter - 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
),
),
)

Related

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

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();
}
}
),

TextField don't resize my alertdialog - Flutter

I leave the entire code fragment, the main idea is to have a textfield that, by using the keyboard, shows me a series of elements, in the description variable, I have that element to select, this works well, the only issue is, how to keep my alertdialog with all the correct notes.
return await Get.generalDialog(
barrierLabel: "Barrier",
barrierDismissible: false,
transitionBuilder: (context, a1, a2, widget) {
return StatefulBuilder(builder: (context, setState) {
return Transform.scale(
scale: a1.value,
child: Opacity(
opacity: a1.value,
child: Dialog(
insetAnimationCurve: Curves.bounceOut,
insetPadding: EdgeInsets.only(right: 20, left: 20),
//backgroundColor: colorFour(),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: SingleChildScrollView(
child: Container(
height: 340,
child: Column(
children: <Widget>[
Container(
alignment: Alignment.topCenter,
height: 50,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
),
padding: EdgeInsets.all(5),
child: Center(
child: Text(
title,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600),
maxLines: 2,
textAlign: TextAlign.center,
),
),
),
SingleChildScrollView(
padding: EdgeInsets.only(left: 10, right: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
Container(
margin: EdgeInsets.only(top: 10),
child: TextFormField(
controller: controller,
decoration: InputDecoration(
border: OutlineInputBorder(
gapPadding: 5.0)),
keyboardType: TextInputType.text,
maxLines: 1,
onChanged: (String cadena) async {
listado = pivote
.where((x) => x.descripcion
.split("/")[value]
.toLowerCase()
.contains(
cadena.toLowerCase()))
.toList();
setState(() {});
},
),
),
Container(
height: 200,
margin: EdgeInsets.only(
top: 10, bottom: 10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(5)),
border: Border.all(
color: Colors.grey, width: 1)),
child: ListView.builder(
padding: const EdgeInsets.all(0.0),
physics: BouncingScrollPhysics(),
itemCount: listado.length,
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return Container(
height: 34,
child: InkWell(
child: SizedBox.expand(
child: Align(
alignment:
Alignment.centerLeft,
child: Padding(
padding:
EdgeInsets.only(
right: 5,
left: 5),
child: Text(
listado[index]
.descripcion
.split(
"/")[value],
textAlign:
TextAlign.left),
),
),
),
onTap: () {
Get.back(result: {
"item": listado[index],
});
}),
);
}),
),
],
)),
],
),
),
),
),
));
});
},
pageBuilder: (context, animation1, animation2) {
return Container();
});
I need to overlay my alertdialog, that is to say that the size does not break my design, this happens after focusing on the textfield
Show us some code to help you out.
In any case, it might make sense to wrap the layout in a SingleChildScrollView.
Here is a very good explanation.
https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html
yourAlertDialog(
context: context,
builder: (BuildContext context) {
return SingleChildScrollView(child: yourchild);
},
);
Your layout should be wrapped in Scrollview , I didn't replicate or run this code but it should be like this:
AlertDialog(
title: Text("title", style: TextStyle(color: ThemeColors.colorPrimary),),
content: Container(
width: double.maxFinite,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: StatefulBuilder(builder: (BuildContext context1, StateSetter setState) {
this.setState = setState;
return Container(
height: 340,
child: Column(
children: <Widget>[
//your container
],
),
),
}),
)),
);

Is there anyway I can add a text below the images in gridview.builder?

need some idea on how to add a box of texts below each of the images in Gridview.builder.
Below is my code.
child: GridView.builder(
primary: false,
padding: const EdgeInsets.all(20),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisSpacing: 10, mainAxisSpacing: 10, crossAxisCount: 2),
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
Widget widget;
switch (index) {
case 0:
widget = Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Image.network(
'https://ezyorder.com.my/uploads/products/t-shirt_man.png'),
);
break;
case 1:
widget = Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Image.network(
'https://ezyorder.com.my/uploads/products/black_full_sleeves.png'),
);
break;
Here is the result.
Wrap your image with Column and add image & text,
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Column(
children: [
Expanded(
child: Image.network(
'https://images.unsplash.com/photo-1633550306397-55382904f350?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3072&q=80',
),
),
const SizedBox(height: 10),
const Text(
'Pop Corn',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w600,
),
)
],
),
);
If you want the Text outside, then wrap your Container with a Column and add text next to the Container.
I think you should use GridTile widget. It has footer property where you can put your text easily
GridTile(
child: Image.network('image url here'),
footer: Text('Title goes here'),
)

How to take available space using container in Flutter

I was trying to make an app with SingleChildScrollView and ListView using below code
SingleChildScrollView(
child: Column(
children: [
maintile(),
Container(
padding: EdgeInsets.all(15.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(75.0),
),
),
child: ListView.builder(
shrinkWrap: true,
primary: false,
itemCount: items.length,
itemBuilder: (context, index) {
return listitem();
},
),
),
],
),
but the listview holding container does not take available space If I provide Expandable around it. is there any way to achieve Container take available space?
Use Expanded for Container parent like this :
Expanded(
child: Container(
child: Text("YOUR_WIDGET"),
),
)
Final Code:
final screenSize = MediaQuery.of(context).size;
return SafeArea(
child: Scaffold(
body: Container(
height: screenSize.height,
width: screenSize.width,
child: Column(
children: [
maintile(),
Expanded(
child: Container(
padding: EdgeInsets.all(15.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(75.0),
),
),
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: items.length,
itemBuilder: (context, index) {
return listitem();
},
),
),
),
],
),
)
),
);

How to display ListTile in flutter

I want to do my interface like the image I show. I want to display the image the put a container to over the image. Now I have a problem with the ListTile I want to show did not come out.
Here is my code:
Scaffold(
appBar: AppBar(
title: Text('Detail'),
),
body: Column(children: <Widget>[
Expanded(
child:
Stack(children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(40), topRight: Radius.circular(40)),),
child: Image.assets('images/photo.png'),
),
Container(
margin: EdgeInsets.only(top: 170),
child: Stack(alignment: Alignment.topCenter, children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(40), topRight: Radius.circular(40)),
color: Colors.white),
)
],
),
),
Positioned(top: 200, left: 8,
child: Column(children: <Widget>[
ListTile(title: Text('Title'), subtitle: Text(''),)
],)
)
],
),
)
],)
);
Anyone can help me?
when scrolling inside Positioned widget you have to give all the positions and scroll direction in listview
Positioned(
top: 190,
bottom: 0,
right: 0,
left: 0,
child: SizedBox(
child: Container(
width: MediaQuery.of(context).size.width,
// height: MediaQuery.of(context).size.height- 190,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft:Radius.circular(20), topRight:Radius.circular(20)) ),
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: 20,
itemBuilder: (BuildContext context, int index){
return ListTile(title: Text("Title $index"),);
},
physics: AlwaysScrollableScrollPhysics(),
shrinkWrap: true,
) ,),
),
)
Replace you code like this
return Scaffold(
appBar: AppBar(
title: Text("title text"),),
body: Stack(children: <Widget>[
Positioned(
top: 0,
child: Image.network("https://upload.wikimedia.org/wikipedia/commons/6/6d/Good_Food_Display_-_NCI_Visuals_Online.jpg",
fit: BoxFit.cover,
height: 200,
width: MediaQuery.of(context).size.width,
),
),
Positioned(
top: 190,
child: Container(
width: MediaQuery.of(context).size.width,
height: 600,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft:Radius.circular(20), topRight:Radius.circular(20)) ),
child: ListView(
shrinkWrap: true,
children: <Widget>[
ListTile(title: Text("Title 1"),),
ListTile(title: Text("Title 1"),),
ListTile(title: Text("Title 1"),),
],) ,),
)
],),
);