How can I use ClipRRect and ListTile inside Row? - flutter

I want to use ClipRRect and ListTile inside Row but it gives an error. Please help me to resolve this error.
Code
body: Column(
children: [
SizedBox(height: 20),
Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))),
child: Row(
children: [
Container(
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image(image: AssetImage('mobile1.jpg'), ),
), ),
ListTile(
title: Text("I Phone 6"),
subtitle: Text("data"),
)
])),
]
), );

Solution:
This is an overflow problem.
It can be solved like this, (has some extras 😉)
return Scaffold(
body: Column(
children: <Widget>[
SizedBox(height: 20),
Card(
// this elevation is purely for shape and is not related to
// solving the problem.
elevation: 10,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
// this padding widget is purely for shape and is not related to
// solving the problem.
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Container(
// here I added some height and width so the image
// follows them and be smaller or larger than the card.
width: 130,
height: 130,
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
// your image, I used a network one.
//
// child: Image(
// image: AssetImage('mobile1.jpg'),
// ),
child: Image.network(
"https://images.pexels.com/photos/699122/pexels-photo-699122.jpeg",
// this line makes the image cover the area, this will
// allow the roundness to appear.
fit: BoxFit.cover,
),
),
),
// this expanded widget makes the list tile take the empty
// space after the image and not any less or more.
Expanded(
child: ListTile(
title: Text("I Phone 6"),
subtitle: Text("data"),
),
),
],
),
),
),
],
),
);
Result:

For the exact solving you need to give the stacktrace. Thought it was a layout overflow issue and I solved as follows:
Column(children: [
SizedBox(height: 20),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Row(
children: [
Container(
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image(
image: AssetImage('mobile1.jpg'),
),
),
),
Expanded(
child: ListTile(
title: Text("I Phone 6"),
subtitle: Text("data"),
),
)
])),
])

Related

Overlap widget inside card widget in Flutter

I wanted to place two widgets (a text and a picture) inside a card, however the picture should go over the card as the image shows:
But I don't know how to make the picture overlapping the card.
This is my code:
Card(
margin: EdgeInsets.zero,
color: Theme.of(context).colorScheme.primary,
clipBehavior: Clip.antiAlias,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
Container(
alignment: Alignment.bottomLeft,
margin: const EdgeInsets.all(12),
height: 70,
child: Text(
"This is a text widget.",
style: Theme.of(context).textTheme.bodyText1,
),
),
Image.asset(
'images/picture1.png',
scale: 5,
),
],
),
),
You can use stack widget along with positioned widget to achieve the UI
Stack
Card
Container
Card(
margin: EdgeInsets.zero,
color: Theme.of(context).colorScheme.primary,
clipBehavior: Clip.antiAlias,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
alignment: Alignment.bottomLeft,
margin: const EdgeInsets.all(12),
height: 70,
child: Text(
"This is a text widget.",
style: Theme.of(context).textTheme.bodyText1,
),
),
Image.asset(
'images/picture1.png',
scale: 5,
),
],
),
],
),
),
you can use stack under card widget

adding rows and columns together using flutter

i am trying to add two-row and 4 columns, I added rows but couldn't add columns, I want them to take the same size so I used expanded()
here is a picture
here is what iam lokking for
i am done with rows but couldn't adds columns
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
title: Text("homepage"),
),
backgroundColor: Colors.yellowAccent[700],
body: SafeArea(
child: Row(
children: [
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(75), // Image radius
child: Image.network('https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(15),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(75), // Image radius
child: Image.network('https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(15),
),
),
],
),
),
),
);
Use GridView.
GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
children: [
...List.generate(
6,
(index) => ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: Container(
color: Colors.yellowAccent[700],
child: SizedBox.fromSize(
size: Size.fromRadius(75), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
),
)
],
),
Using Row and Column, you need to provide fixed height for each Row.
body: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) => Column(
children: [
SizedBox(
height: constraints.maxHeight * .3,
child: Row(
children: [
...List.generate(
2,
(index) => Expanded(
child: Container(
color: Colors.yellowAccent[700],
padding: EdgeInsets.all(12),
child: ClipRRect(
borderRadius:
BorderRadius.circular(20), // Image border
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
),
)
],
),
),
SizedBox(
height: constraints.maxHeight * .3,
child: Row(
children: [
...List.generate(
2,
(index) => Expanded(
child: Container(
color: Colors.yellowAccent[700],
padding: EdgeInsets.all(12),
child: ClipRRect(
borderRadius:
BorderRadius.circular(20), // Image border
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
),
)
],
),
),
],
),
),
),
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
title: Text("homepage"),
),
backgroundColor: Colors.yellowAccent[700],
body: SafeArea(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9' ,
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
],
),
Column(
children: [
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://t3.ftcdn.net/jpg/04/33/08/02/360_F_433080252_BWd42il6gVUmQaXIkASbUrHfKMV3fnqg.jpg',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
],
),
],
),
),
),
);
}
}
this is the answer
I just added a column inside a row with expanded so it take the same size

Flutter type 'Null' is not a subtype of type 'String' after navigating

I have 4 screens (home, Excursion, Spa, detail) and I want to navigate from multiple to one detailed screen (from home, Excursion, Spa to detail) it work fine at first but after it give me: type 'Null' is not a subtype of type 'String' Error, if I navigate from the "Excursion" or "Spa" page to the "Detail" page. but it work fine if I navigate from the home the detail screen.
this is the Home screen
Container(
child: GestureDetector(
onTap: ()=>Navigator.pushNamed(context, '/Detail',arguments:{
'previousScreenData':dataList_home[index],
}
),
child: Card(
child: Center(
child: Column(
children:<Widget>[
Image(
image: NetworkImage(dataList_home[index]["PHOTO"]),
height: 250,
fit:BoxFit.fill,
),
SizedBox(height: 10.0),
Column(
children:<Widget>[
Text(
dataList_home[index]["LIBELLE"],
),
]
),
SizedBox(height: 10.0),
Column(
children:<Widget>[
Text(
dataList_home[index]["PRICE_AD"],
),
]
),
SizedBox(height: 10.0),
Row(
mainAxisAlignment:MainAxisAlignment.spaceEvenly,
children:<Widget>[
for ( var i in iconList ) Row(
children:<Widget>[
FaIcon(iconMapping [i.toString()] ?? FontAwesomeIcons.question,),
]
),
],
),
SizedBox(height: 15.0),
]
),
),
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
),
),
);
this is the Spa screen
Container(
child: GestureDetector(
onTap: ()=>Navigator.pushNamed(context, '/Detail',arguments:{
'previousScreenData':dataList_spa[index],
}),
child: Card(
child: Center(
child: Column(
children:<Widget>[
Image(
image: NetworkImage(dataList_spa[index]["PHOTO"]),
height: 250,
fit:BoxFit.fill,
),
SizedBox(height: 10.0),
Column(
children:<Widget>[
Text(
dataList_spa[index]["LIBELLE"],
),
]
),
SizedBox(height: 10.0),
Column(
children:<Widget>[
Text(
dataList_spa[index]["PRICE_AD"],
),
]
),
SizedBox(height: 10.0),
Row(
mainAxisAlignment:MainAxisAlignment.spaceEvenly,
children:<Widget>[
for ( var i in iconList ) Row(
children:<Widget>[
FaIcon(iconMapping [i.toString()] ?? FontAwesomeIcons.question),
]
),
],
),
SizedBox(height: 15.0),
]
),
),
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
),
),
);
This is the Detail Screen
Widget build(BuildContext context) {
dataMap=ModalRoute.of(context)?.settings.arguments as Map;//We recieve the data as a Map from the home screen
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/NizdG.jpg

show Image over image flutter

Need to show image above other image outside the widget margin.
I tried using stack, but it not coming outside.
Stack(children: <Widget>[
Container(child: Image.asset('assets/discover.png')),
Row(
children: <Widget>[
Expanded(child: Text(''), flex: 9),
Expanded(
child: ClipRRect(
borderRadius: new BorderRadius.circular(80.0),
child: Image.asset('assets/user.jpg')),
flex: 6,
),
Expanded(child: Text(''), flex: 9)
],
),
]);
Below source code works for your scenario. You have to give top padding for the image's container and make the entire stack's alignment as topCenter.
Additional things:
Consider giving height and width for the circled image.
Keep the big image widget in AspectRatio widget to occupy the full width of its parent widget and give fit property as well for showing entire image in the right fit.
.
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 40),
child: AspectRatio(aspectRatio: 1, child: Image.asset('assets/discover.png', fit: BoxFit.cover),),
),
ClipRRect(
borderRadius: new BorderRadius.circular(40.0),
child: Image.asset('assets/user.jpg', height: 80, width: 80),
),
],
)
return Scaffold(
appBar: AppBar(
title: const Text('Flutter demo'),
),
body: Container(
padding: EdgeInsets.fromLTRB(5, 10, 5, 10),
alignment: Alignment.topCenter,
child: Stack(children: <Widget>[
Container(
margin: EdgeInsets.only(top: 30),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.network(
'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQGLanNnFsLi3QnQFdh-k-mkwG6yrEEXhorSoElObizTnP0_8rR')),
),
Align(
alignment: Alignment.topCenter,
child: CircleAvatar(
radius: 30.0,
backgroundImage: NetworkImage(
'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSIekuJOwtOWtZl9QX3t46Yz_7RCZ4Kpebnugsst2OFfNl-SGjf'),
backgroundColor: Colors.grey,
),
)
]),
));
Stack(children: <Widget>[
Container(
margin: EdgeInsets.only(top: 50.0),
child: Image.network(
'https://cdn.pixabay.com/photo/2015/06/19/21/24/the-road-815297__340.jpg'),
),
Row(
children: <Widget>[
Expanded(child: Text(''), flex: 9),
Expanded(
child: ClipRRect(
borderRadius: new BorderRadius.circular(80.0),
child: Image.asset('assets/ic_profile.png'),
),
flex: 6,
),
Expanded(child: Text(''), flex: 9)
],
)
]),

Flutter- How to use image in container?

I am building an app and I am using a Container to design a card but here is a thing image should be 1/3 of the container and not fill up the entire container.
Here is the code for the container:
Container(
height: 240,
width: 160,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('images/rest.jpg'),fit: BoxFit.cover),
borderRadius: BorderRadius.all(Radius.circular(10)),
color: Color(0xFFFDEEDD),
),
child: Column(
children: <Widget>[
Text('Hello'),
Row(
children: <Widget>[
Text('World'),
Text('4.2'),
],
)
],
),
),
Card I am trying to replicate
I think it would be better to use a ClipRRect here instead. If you use material, you can also use ListTile :
return Material(
child: Center(
child: Container(
color: Colors.black12,
width: 250,
child: Column(
mainAxisSize: MainAxisSize.min,
children:[
ClipRRect(
child:Image.network("https://via.placeholder.com/250"),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
ListTile(
title: Text("The fifties"),
subtitle: Text("Subtitle"),
)
]
)
)
)
);