flutter: Is there a way to reuse a widget? - flutter

I have two widgets which are basically the same, except their color. They are list tile in list view builder. There is a checking to show in grey or red. The only property to be changed is color. I know that there is copyWith() function, but it seems that cannot be used in this case.
How can I reuse the below widget?
Widget listTile = Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 8.0, 0),
child: ListTile(
title: Text(
message.title),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(message.name),
Row(
children: <Widget>[
Icon(
Icons.alarm_on,
color: Colors.redAccent,
size: 16,
),
Text(message.time),
],
)
],
),
),
),
),
);

Make a function which takes the color as a parameter..and return your widget from that function..
Something like this..
customWidget( Color color){
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 8.0, 0),
child: ListTile(
title: Text(
message.title),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(message.name),
Row(
children: <Widget>[
Icon(
Icons.alarm_on,
//color: Colors.redAccent,
color: color,
size: 16,
),
Text(message.time),
],
)
],
),
),
),
),
);
}
And whenever you want to use it..do it this way..
customWidget(Colors.red)
Hope it solves your issue..feel free to ask for clarifications :)

Instead of making it a variable, you can make it a method and then pass the color parameter to it.
Widget buildWidget(Color color) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: color, // Use your color parameter here
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 8.0, 0),
child: ListTile(
title: Text(
message.title),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(message.name),
Row(
children: <Widget>[
Icon(
Icons.alarm_on,
color: Colors.redAccent,
size: 16,
),
Text(message.time),
],
)
],
),
),
),
),
);
}
You can also pass along the message object you are using as a parameter to the function
So your ListView.builder will look like:
ListView.builder(
..., // other properties
itemBuilder: (context, index) => buildWidget(/*Your params here*/),
),

Related

Can't give a width to message in a Flutter chat

I want to make the background fit the text like instagram chat or telegram but it simply does not work, please help
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: ListView(
children: tasks
.map((e) => Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
decoration: BoxDecoration(
color: Colors.green,
),
child: Text(
e,
style: TextStyle(fontSize: 25),
),
),
))
.toList()),
)
],
),
),
The result
You can do that by wrapping Padding with Align and choose your preferred alignment.
for instance:
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: Colors.green,
),
child: Text(
e,
style: TextStyle(fontSize: 25),
),
),
),
)

There are constantly overflows on the card structure

I just started flutter. I tried to make a card structure but I think it is quite wrong. I could never fix it. I am using Gridview extend. In this way, the column numbers change dynamically as the screen gets smaller or larger. but i keep getting overflow error what should i do.
var response = sepet.itemsCount[item.name];
return SizedBox(
child: Padding(
padding: EdgeInsets.all(0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: InkWell(
customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
onTap: () {},
child: Column(
children: <Widget>[
ListTile(
title: Text(item.name ?? ''),
subtitle: Text(item.defaultPrice.toString() + '\$'),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
countChanger(sepet, false, item),
Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: Text(
response != null ? response.toString() : '0',
style: TextStyle(fontSize: 18.0),
),
),
countChanger(sepet, true, item),
],
),
ButtonTheme(
height: 25,
minWidth: 25,
child: ElevatedButton(
onPressed: () {
!isAdded
? sepet.sepeteEkle(item)
: sepet.deleteItem(item);
},
style: ElevatedButton.styleFrom(
primary: !isAdded
? Colors.teal
: Colors.red,
),
child: Text(!isAdded ? 'Ekle' : 'Çıkar'),
),
),
],
),
)
],
),
),
),
],
),
),
);
My gridview extend structure is like this
child: GridView.extent(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
maxCrossAxisExtent: 250.0,
crossAxisSpacing: 20.0,
mainAxisSpacing: 20.0,
children: List.generate(foods!.length, (index) {
return itemCard(foods[index].menuItem ?? MenuItem(), value);
}),
The question you need to answer is what would you like to happen if the width of that card is so small? Do you want a different arrangement of those elements? If you do decide on what that would look like and check the constraint with LayoutBuilder Or the whole screen width with MediaQuery whatever you feel is best. You could also make that bit scroll horizontally by using SingleChildScrollView. This is a design decision. You must image what things look like when screen size changes, and be as deliberate as possible with the responsiveness rather then to just try to find some magic widget which we are all guilty of doing sometimes.
Try below code hope its helpful to you I have try similar to your code and add your widgets in Expanded or Flexible Widgets.
flexible widgets
expanded Widgets
GridView.builder(
padding: const EdgeInsets.all(8),
itemCount: 4,
itemBuilder: (ctx, i) {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text('data'),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
margin: EdgeInsets.all(10),
height: 35.0,
width: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.grey,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
InkWell(
child: Icon(Icons.remove, color: Colors.green),
onTap: () {},
),
Spacer(),
Text(
'0',
style: Theme.of(context)
.textTheme
.subtitle2!
.copyWith(fontSize: 16.0),
),
Spacer(),
InkWell(
child: Icon(
Icons.add,
color: Colors.green,
),
onTap: () {},
),
],
),
),
),
Expanded(
child: ElevatedButton(
onPressed: () {},
child: Text(
'Sub Total',
style: TextStyle(
fontSize: 15,
),
),
),
),
],
),
],
),
);
},
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 170.0,
mainAxisExtent: 93,
),
),
Your Result screen like->

ScrollView RenderFlex overflow - Flutter

I'm new to Flutter and have been trying to clone a screen that requires a scroll architecture.Here is the link of the screen that i'm working on. https://i.stack.imgur.com/1OW2b.pngThe code is as below.PS: Ignore the fields that are incomplete. As soon as I get the scroll view, i'll add the functionalities afterwards.
Scaffold(
body: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(15.0, 40.0, 15.0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: const <Widget>[
Icon(Icons.menu),
Image(), //Asset image
],
),
Row(
children: <Widget>[
const Icon(Icons.notifications_none),
const SizedBox(width: 27.0),
CircleAvatar(
child: Text("JM"),
),
],
)
],
),
Row(
children: const <Widget>[
Icon(Icons.arrow_back),
SizedBox(width: 20.0),
Text("Public page"),
],
),
const SizedBox(
height: 20.0,
),
const Text(" Please fill the form following the proper order."),
const SizedBox(height: 10.0),
OverviewWidget(), //Widget with lots of TextFormField
SizedBox(height: 10.0),
DescriptionWidget(), //Widget with lots of TextFormField
],
),
),
Align([enter image description here][1]
alignment: Alignment.bottomCenter,
child: GestureDetector(
onTap: () {
print("Hello");
},
child: Container(
height: 130.0,
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.shade400,
blurRadius: 10,
spreadRadius: 1,
)
],
),
child: Container(
margin: const EdgeInsets.only(top: 10.0, bottom: 30.0),
decoration: BoxDecoration(
color: Colors.green.shade400,
borderRadius: BorderRadius.circular(35),
),
child: const Padding(
padding: EdgeInsets.symmetric(
vertical: 15.0,
horizontal: 150.0,
),
child: Text(
"Save",
style: TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w600),
),
),
),
),
),
),
],
),
);
So far, i've only created the Overview and Description widgets and i'm already getting RenderFlex overflow error. I tried wrapping the very first Column widget with a SingleChildScrollView widget but it can be noticed that the Save button at the bottom should stay fixed. I tried wrapping the whole widget with Stack widget instead of a Column widget but it didn't help either. I also used ListView widget but got the same results.What shall I do to achieve this view?
I guess you had all the elements but did not quite manage to use them as needed.
Your screen is composed of two important layout:
A stack (containing a button on top of a scrollable widget)
The scrollable widget
The stack has to be a stack, the scrollable can be anything but in your case SingleChildScrollView+Column seems the best choice.
Here is the concrete implementation:
Scaffold(
body: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(15.0, 40.0, 15.0, 0),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(bottom: 100.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(Icons.menu),
Container(
height: 100,
width: 100,
color: Colors.redAccent,
),
//Asset image
],
),
Row(
children: <Widget>[
const Icon(Icons.notifications_none),
const SizedBox(width: 27.0),
CircleAvatar(
child: Text("JM"),
),
],
)
],
),
Row(
children: const <Widget>[
Icon(Icons.arrow_back),
SizedBox(width: 20.0),
Text("Public page"),
],
),
const SizedBox(
height: 20.0,
),
const Text(" Please fill the form following the proper order."),
const SizedBox(height: 10.0),
Container(
height: 400,
color: Colors.blueAccent,
), //Widget with lots of TextFormField
SizedBox(height: 10.0),
Container(
height: 400,
color: Colors.greenAccent,
), //Widget with lots of TextFormField
],
),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
onTap: () {
print("Hello");
},
child: Container(
height: 130.0,
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.shade400,
blurRadius: 10,
spreadRadius: 1,
)
],
),
child: Container(
margin: const EdgeInsets.only(top: 10.0, bottom: 30.0),
decoration: BoxDecoration(
color: Colors.green.shade400,
borderRadius: BorderRadius.circular(35),
),
child: const Padding(
padding: EdgeInsets.symmetric(
vertical: 15.0,
horizontal: 150.0,
),
child: Text(
"Save",
style: TextStyle(
color: Colors.white, fontSize: 17, fontWeight: FontWeight.w600),
),
),
),
),
),
),
],
),
)
Note that you have to put a bottom padding inside the SingleChildScrollView to take into account the button. This is fine in your case since the button has a static height. However if you need something more fancy you might want to check How to create a scroll view with fixed footer with Flutter? as #Csisanyi suggested
Consider wrapping the Column with an Expanded widget
You can also check out this flutter doc. It addresses this common issue in detail.
https://flutter.dev/docs/testing/common-errors
Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(15.0, 40.0, 15.0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(Icons.menu),
// Image(), //Asset image
Image.asset(
'assets/ocean.jpg',
height: kToolbarHeight,
/// make sure of image height
fit: BoxFit.fitHeight,
),
],
),
Row(
children: <Widget>[
const Icon(Icons.notifications_none),
const SizedBox(width: 27.0),
CircleAvatar(
child: Text("JM"),
),
],
)
],
),
Row(
children: const <Widget>[
Icon(Icons.arrow_back),
SizedBox(width: 20.0),
Text("Public page"),
],
),
const SizedBox(
height: 20.0,
),
const Text(
" Please fill the form following the proper order."),
const SizedBox(height: 10.0),
//todo: OverviewWidget(), //Widget with lots of TextFormField
...List.generate(22, (index) {
return TextField(
decoration: InputDecoration(hintText: "1st $index"),
);
}),
SizedBox(height: 10.0),
//todo: DescriptionWidget(), //Widget with lots of TextFormField
...List.generate(22, (index) {
return TextField(
decoration: InputDecoration(hintText: "2st $index"),
);
}),
],
),
),
Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
onTap: () {
print("Hello");
},
child: Container(
height: 130.0,
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.shade400,
blurRadius: 10,
spreadRadius: 1,
)
],
),
child: Container(
margin: const EdgeInsets.only(top: 10.0, bottom: 30.0),
decoration: BoxDecoration(
color: Colors.green.shade400,
borderRadius: BorderRadius.circular(35),
),
child: const Padding(
padding: EdgeInsets.symmetric(
vertical: 15.0,
horizontal: 150.0,
),
child: Text(
"Save",
style: TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w600),
),
),
),
),
),
),
],
),
),
),

how can i Create space between two text fname and contact?

I want to create space between 'fname' and 'contact'. It is displaying in this format :- 1: Mayank , 2: 77177.
But I want to display the text in this format :-
1: Mayank,
2:77177
Widget buildResultCard(data) {
return Scaffold(
body: Container(
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.purpleAccent,width: 2),
borderRadius: BorderRadius.circular(10),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: <Widget>[
Container(
width:150,
height: 200,
padding: const EdgeInsets.only(top: 2.0, bottom: 5.0),
child: Row(children: <Widget>[
Image.network(data['image'],width: 150, height: 150,fit: BoxFit.cover,),
Spacer(),
]),
),
SizedBox(width: 10),
Text(data['fname'], style: new TextStyle(fontSize: 15.0,),),
// Want to display one next the other.
Text(data['contact'], style: new TextStyle(fontSize: 15.0,height: 1.5),),
],
),
),
),
),
);
}
You could use one of this two options:
Wrap your texts in a Column widget.
\n Adds an "end of line"
Example (2):
new Text(':-\n\n${data['fname']},\n\n${data['contact']}')
This might work:
return Scaffold(
body: Container(
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.purpleAccent,width: 2),
borderRadius: BorderRadius.circular(10),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: <Widget>[
Container(
width:150,
height: 200,
padding: const EdgeInsets.only(top: 2.0, bottom: 5.0),
child: Row(children: <Widget>[
Image.network(data['image'],width: 150, height: 150,fit: BoxFit.cover,),
Spacer(),
]),
),
SizedBox(width: 10),
Column(mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(data['fname'], style: new TextStyle(fontSize: 15.0,),),
// Want to display one next the other.
Text(data['contact'], style: new TextStyle(fontSize: 15.0,height: 1.5),),
],
),
],
),
),
),
),
);

flutter list error The argument type 'List' can't be assigned to parameter type 'String'

I get an error that says;
The argument type 'List' can't be assigned to parameter type 'String'
on widget.storePageImage, widget.storePageItemName, and widget.storePageItemPrice.
How can I make this work?
This is what I'm trying to achieve;
once a store in home page has been clicked(https://imgur.com/a/0YiMUHj) it should direct it to that individual stores page(https://imgur.com/a/KbsIepO).
import 'package:flutter/material.dart';
import 'package:filename/src/homescreen.dart';
import 'package:filename/data/Store_list.dart';
class StoresPage extends StatefulWidget {
String storeName;
String storeDeliveryTime;
String deliveryCharges;
List<String> storePageImage;
List<String> storePageItemName;
List<String> storePageItemPrice;
StoresPage({
this.storeName, this.storeDeliveryTime, this.deliveryCharges,
this.storePageImage, this.storePageItemName, this.storePageItemPrice
});
#override
_StoresPageState createState() => _StoresPageState();
}
class _StoresPageState extends State<StoresPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
Container(
padding: EdgeInsets.only(right: 15.0, top: 9.0, left: 10.0),
margin: EdgeInsets.only(bottom: 10.0),
child: Row(
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 20.0, right:
5.0),
child: GestureDetector(
onTap: (){Navigator.push(
context,
MaterialPageRoute(builder: (context) =>
HomeScreen()),
);},
child: Icon(Icons.navigate_before, color:
Colors.black87,)),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("You're now", style: TextStyle(color:
Colors.grey),),
Row(
children: <Widget>[
Text("Shopping at", style: TextStyle(fontSize:
16.0, fontWeight: FontWeight.bold),),
SizedBox(width: 5.0,),
Text(widget.storeName, style:
TextStyle(fontSize: 16.0, fontWeight:
FontWeight.bold),),
],
),
],
),
Spacer(),
Container(
height: 60,
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage('assets/images/profilepc.png'),
),
),
),
],
),
),
Container(
margin: EdgeInsets.only(bottom: 25.0),
height: 35.0,
width: 380.0,
child: Padding(
padding: const EdgeInsets.only(left: 15.0, right: 15.0),
child: TextField(
style: TextStyle(fontSize: 15.0),
decoration: InputDecoration(
filled: true,
fillColor: Color(0xFFEEEEEE),
contentPadding: EdgeInsets.symmetric(horizontal: 5.0,
vertical: 5.0),
hintText: "Search ${widget.storeName}",
prefixIcon: Icon(Icons.search, color: Colors.black,),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(30.0))),
),
),
),
),
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(widget.storeName, style: TextStyle(fontSize:
25.0),)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.motorcycle),
SizedBox(width: 7.0),
Text(widget.deliveryCharges),
SizedBox(width: 20.0,),
Icon(Icons.update),
SizedBox(width: 5.0),
Text(widget.storeDeliveryTime),
],
),
Padding(
padding: const EdgeInsets.only(top: 10.0, bottom: 1.0),
child: Divider(height: 20.0, color: Colors.grey,),
),
],
),
SingleChildScrollView(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 10.0, top: 7.0),
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(widget.storePageImage),
),
),
),
),
Text(widget.storePageItemName),
Spacer(),
Padding(padding: const EdgeInsets.only(top: 52.0,
right: 10.0),
child: Column(children: <Widget>[
Text(widget.storePageItemPrice),
],),
),
],
),
],
),
),
],
),
);
}
}
Data file
class Stores {
String storeName;
String storeImage;
String storeDeliveryTime;
String deliveryCharges;
List<String> storePageImage;
List<String> storePageItemName;
List<String> storePageItemPrice;
Stores.list({this.storeName, this.storeDeliveryTime
this.storeImage, this.deliveryCharges, this.storePageImage,
this.storePageItemName, this.storePageItemPrice});
}
List<Stores> storesList = [
Stores.list(
storeName: "Store 1",
storeImage: "assets/images/store1front.jpg",
storeDeliveryTime: "25 min",
deliveryCharges: "£3.90",
storePageImage: ["assets/images/1.png","assets/images/2.png",
"assets/images/3.png","assets/images/4.png"],
storePageItemName: ["Black TSHIRT","Khaki T-SHIRT","Grey Knit
Notch Neck","Teal Polo Shirt" ],
storePageItemPrice: ["£17.99","17.99","17.99","17.99"]
),
Stores.list(
storeName: "STORE2",
storeImage: "assets/images/STORE2front.jpg",
storeDeliveryTime: "25 min",
deliveryCharges: "£2.90",
storePageImage:
["assets/images/store2_1.png","assets/images/store2_2.png",
"assets/images/store2_3.png","assets/images/store2_4.png"],
storePageItemName: ["WHITE TSHIRT","orange T-SHIRT","Grey
shirt", "mint tea Polo Shirt" ],
storePageItemPrice: ["£18.99","10.99","16.99","13.99"]),];
The reason why you're getting the error The argument type 'List' can't be assigned to parameter type 'String' is because the method expects a String, but a List is being used.
The logs points out the parameters causing the issue: widget.storePageImage, widget.storePageItemName, and widget.storePageItemPrice. These parameters are used here.
SingleChildScrollView(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 10.0, top: 7.0),
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(widget.storePageImage),
),
),
),
),
Text(widget.storePageItemName),
Spacer(),
Padding(padding: const EdgeInsets.only(top: 52.0,
right: 10.0),
child: Column(children: <Widget>[
Text(widget.storePageItemPrice),
],),
),
],
),
],
),
),
From what I can see, it seems that you're trying to create a List of Widgets displaying store page items and its prices. What you can do here is use ListView.builder() to create a List of Widgets for store page items.
ListView.builder(
padding: const EdgeInsets.all(8),
// assuming that storePageImage, storePageItemName, storePageItemPrice
// has the same length. Otherwise, add safety checks for index OutOfBound errors
itemCount: widget.storePageItemName.length,
itemBuilder: (BuildContext context, int index) {
return Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 10.0, top: 7.0),
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(widget.storePageImage[index]),
),
),
),
),
Text(widget.storePageItemName[index]),
Spacer(),
Padding(
padding: const EdgeInsets.only(top: 52.0, right: 10.0),
child: Column(
children: <Widget>[
Text(widget.storePageItemPrice[index]),
],
),
),
],
);
},
)