Flutter fetch data from rest with reuse code - rest

I try to reuse this codes:"https://github.com/rajayogan/flutterui-plants" and i will fetch data with a rest api.
I don't know how to.
Someone please help or explain.
Thanks by advance.
Best regards

i try to explain my problem with code:
in flutterui-plants /plantlist.dart we have this code:
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
Container(
height: 350.0,
child: ListView(
padding: EdgeInsets.only(left: 25.0),
controller: _scrollController,
scrollDirection: Axis.horizontal,
children: <Widget>[
getPlantCard(
'assets/whiteplant.png', '25', 'OUTDOOR', 'Aloe Vera'),
SizedBox(width: 15.0),
getPlantCard('assets/smallplant.png', '25', 'INDOOR', 'Ficus'),
SizedBox(width: 15.0),
getPlantCard('assets/smallplant.png', '25', 'INDOOR', 'Ficus'),
SizedBox(width: 15.0),
],
),
),
Padding(
padding: EdgeInsets.only(left: 25.0, top: 10.0),
child: Text(
'Description',
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.black,
fontSize: 17.0,
fontWeight: FontWeight.w500),
),
),
Padding(
padding: EdgeInsets.only(left: 25.0, top: 10.0),
child: Text(
description,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
),
),
)
],
);
}
getPlantCard(
String imgPath, String price, String plantType, String plantName) {
return Stack(
children: <Widget>[
Container(
height: 325.0,
width: 225.0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Color(0xFF399D63)),
height: 250.0,
width: 225.0,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Column(
children: <Widget>[
SizedBox(height: 10.0),
Text(
'FROM',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
fontWeight: FontWeight.w600,
color: Color(0xFF8AC7A4)),
),
Text(
'\$' + price,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 20.0,
fontWeight: FontWeight.w400,
color: Colors.white),
)
],
),
SizedBox(width: 10.0)
],
),
Image(
image: AssetImage(imgPath),
height: 165.0,
),
Row(
children: <Widget>[
SizedBox(width: 25.0),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
plantType,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
fontWeight: FontWeight.w600,
color: Color(0xFF8AC7A4)),
),
Text(
plantName,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 20.0,
fontWeight: FontWeight.w600,
color: Colors.white),
)
],
),
],
),
SizedBox(height: 10.0),
Row(
children: <Widget>[
SizedBox(width: 25.0),
Container(
height: 30.0,
width: 30.0,
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFF8AC7A4),
style: BorderStyle.solid,
width: 0.5),
borderRadius: BorderRadius.circular(5.0),
color: Color(0xFF399D63)),
child: Icon(Icons.wb_sunny,
color: Colors.white.withOpacity(0.4), size: 20.0),
),
SizedBox(width: 15.0),
Container(
height: 30.0,
width: 30.0,
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFF8AC7A4),
style: BorderStyle.solid,
width: 0.5),
borderRadius: BorderRadius.circular(5.0),
color: Color(0xFF399D63)),
child: Icon(Icons.branding_watermark,
color: Colors.white.withOpacity(0.4), size: 20.0),
),
SizedBox(width: 15.0),
Container(
height: 30.0,
width: 30.0,
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFF8AC7A4),
style: BorderStyle.solid,
width: 0.5),
borderRadius: BorderRadius.circular(5.0),
color: Color(0xFF399D63)),
child: Icon(Icons.hot_tub,
color: Colors.white.withOpacity(0.4), size: 20.0),
),
SizedBox(width: 10.0),
InkWell(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => PlantDetail()
));
},
child: Container(
height: 30.0,
width: 30.0,
decoration: BoxDecoration(color: Color(0xFF399D63)),
child: Icon(Icons.help_outline,
color: Colors.white.withOpacity(0.4), size: 20.0),
),
)
],
)
],
),
),
),
Padding(
padding: EdgeInsets.only(left: 90.0, top: 300.0),
child: Container(
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0), color: Colors.black),
child:
Center(child: Icon(Icons.shopping_cart, color: Colors.white)),
),
)
],
);
}
}
I tried to fectch data like this:
i add this code
List<Product> parseProducts(String responseBody) {
final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();
return parsed.map<Product>((json) =>Product.fromMap(json)).toList();
}
Future<List<Product>> fetchProducts() async {
final response = await http.get('http://192.168.1.12:8000/plants/',headers: {
"Authorization": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTYxODM2NjUsImlhdCI6MTU5NjA5NzI2MCwic3ViIjoyfQ.Hz8gbT0bgaj7rNhs4SYl2I8iWxvn5sZ_liqXmHofgSE"
});
if (response.statusCode == 200) {
return parseProducts(response.body);
} else {
throw Exception('Unable to fetch products from the REST API');
}
}
and replace this block
getPlantCard(
'assets/whiteplant.png', '25', 'OUTDOOR', 'Aloe Vera'),
SizedBox(width: 15.0),
getPlantCard('assets/smallplant.png', '25', 'INDOOR', 'Ficus'),
SizedBox(width: 15.0),
getPlantCard('assets/smallplant.png', '25', 'INDOOR', 'Ficus'),
SizedBox(width: 15.0),
by this
FutureBuilder<List<Product>>(
future: product,
builder: (context, snapshot) {
if (snapshot.hasData) {
return getPlantCard('assets/'+snapshot.data[0].image,snapshot.data[0].price,snapshot.data[0].outorindoor,snapshot.data[0].name);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
// By default, show a loading spinner.
return CircularProgressIndicator();
}),
its works for one result but how to have all getplant() list .
I hope i was clear this time and thanks by advance

Related

How to get value from reference field in firestore flutter and display in stream builder?

i have a firestore collection named 'orders'. It has user details as field name 'uid'. The field 'uid' is a reference to user data present in 'users' collections. No i have to display username along with order details. So i need to get data from the reference field. i'm using Streambuilder to display data. Here is what i did:
Widget build(BuildContext context) {
Map UserSnapshot = Map();
return Scaffold(
body: StreamBuilder(
stream:_db.collection('users').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>> UsersSnapshot) {
UsersSnapshot.data?.docs.forEach((element) {
UserSnapshot[element.id] = element;
});
return StreamBuilder(
stream:_db.collection('orders').where(
'driverId', isEqualTo: sp.getString('uid')).snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> OrdersSnapshot) {
if (!OrdersSnapshot.hasData) return const Text('Loading...');
return ListView.builder(
itemCount: OrdersSnapshot.data!.docs.length,
itemBuilder:(context,index) {
var documentSnapshot= OrdersSnapshot.data!.docs[index].data() as Map<String,dynamic>;
return Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Container(
width: MediaQuery.of(context).size.width,
height: 260,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.black38, width: 1)),
child: Column(
children: [
Row(
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Container(
height: 60,
width: 60,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
border: Border.all(color: Colors.black12)),
child: Image.network(
'https://indiaeducationdiary.in/wp-content/uploads/2020/10/IMG-20201024-WA0014.jpg')),
),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Paradise Multicuisine Restaurant',
style: GoogleFonts.poppins(
fontWeight: FontWeight.bold, fontSize: 14),
overflow: TextOverflow.ellipsis,
),
Text(
'372,Kamarajar Salai, Karaikal',
style: GoogleFonts.poppins(
fontWeight: FontWeight.w400,
fontSize: 11,
color: hexStringToColor('636567')),
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
DottedLine(
dashColor: Colors.black26,
dashGapLength: 10,
),
Padding(
padding: EdgeInsets.all(20),
child: Container(
width: MediaQuery.of(context).size.height,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.account_circle),
SizedBox(
width: 7,
),
Text(
UserSnapshot[documentSnapshot['uid']['fullname']] ?? 'Deleted User',
style: GoogleFonts.poppins(
fontSize: 12,
fontWeight: FontWeight.w500,
color: hexStringToColor('636567')),
),
SizedBox(width: 3),
Text(
'#'+ documentSnapshot['orderId'],
style: GoogleFonts.poppins(
fontSize: 12,
fontWeight: FontWeight.w500,
color: hexStringToColor('636567')),
)
],
),
Container(
width: MediaQuery.of(context).size.width * 0.90,
child: Row(
children: [
Icon(Icons.location_on_rounded),
SizedBox(
width: 7,
),
Expanded(
child: Text(
'6/8, RR Colony, Ambedkar Street, Karaikal',
style: GoogleFonts.poppins(
fontSize: 12,
fontWeight: FontWeight.w500,
color: hexStringToColor('636567')),
overflow: TextOverflow.clip,
maxLines: 4,
),
),
],
),
),
SizedBox(height: 20,),
Row(
children: [
Container(
decoration: BoxDecoration(
color: hexStringToColor('aeaeae'),
borderRadius: BorderRadius.circular(5)
),
width: 80,
height: 20,
child: Row (
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('3 Items',
style: GoogleFonts.poppins(fontSize: 10, fontWeight: FontWeight.w500),
)
],
),
),
SizedBox(width: 20,),
Container(
decoration: BoxDecoration(
color: hexStringToColor('aeaeae'),
borderRadius: BorderRadius.circular(5)
),
width: 80,
height: 20,
child: Row (
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("₹"+documentSnapshot['grandTotal'].toString(),
style: GoogleFonts.poppins(fontSize: 10, fontWeight: FontWeight.w500),
)
],
),
),
],
),
Align(
child: ElevatedButton(onPressed: ()=>{},
child: Text('View Details'),
style: ElevatedButton.styleFrom(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)
),
textStyle: GoogleFonts.poppins(fontWeight: FontWeight.w400,fontSize: 14)
),
),
alignment: Alignment.centerRight,
)
],
),
),
)
],
),
),
);
}
);
}
);
},
)
);
}}
You can iterate over the snapshots using asyncMap.
For example:
stream:_db.collection('users').snapshots().asyncMap((event) async {
event.docs.map((userDoc) {
var userData = userDoc.data() as Map<String, dynamic>;
var referenceSnapshot = userData["someReference"].get();
});
})

Flutter 'child' and 'duration' parameter aren't defined

I don't understand why in Positioned widget, I get an error that child parameter isn't defined as well as in AnimatedContainer the 'duration' parameter isn't defined.
I checked the official documentation first, but don't know why it's not working.
https://api.flutter.dev/flutter/widgets/Positioned-class.html
https://api.flutter.dev/flutter/widgets/AnimatedContainer-class.html
class _DetailsPageState extends State<DetailsPage> {
var selectedCard = 'WEIGHT';
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF7A9BEE),
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(Icons.arrow_back_ios),
color: Colors.white,
),
backgroundColor: Colors.transparent,
elevation: 0.0,
title: Text('Details',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 18.0,
color: Colors.white)),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.more_horiz),
onPressed: () {},
color: Colors.white,
)
],
),
body: ListView(children: [
Stack(children: [
Container(
height: MediaQuery.of(context).size.height - 82.0,
width: MediaQuery.of(context).size.width,
color: Colors.transparent),
Positioned(
top: 75.0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(45.0),
topRight: Radius.circular(45.0),
),
color: Colors.white),
height: MediaQuery.of(context).size.height - 100.0,
width: MediaQuery.of(context).size.width)),
Positioned(
top: 30.0,
left: (MediaQuery.of(context).size.width / 2) - 100.0,
child: Hero(
tag: widget.heroTag,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.heroTag),
fit: BoxFit.cover)),
height: 200.0,
width: 200.0))),
Positioned(
top: 250.0,
left: 25.0,
right: 25.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(widget.foodName,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 22.0,
fontWeight: FontWeight.bold)),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(widget.foodPrice,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 20.0,
color: Colors.grey)),
Container(height: 25.0, color: Colors.grey, width: 1.0),
Container(
width: 125.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(17.0),
color: Color(0xFF7A9BEE)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
onTap: () {},
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
color: Color(0xFF7A9BEE)),
child: Center(
child: Icon(
Icons.remove,
color: Colors.white,
size: 20.0,
),
),
),
),
Text('2',
style: TextStyle(
color: Colors.white,
fontFamily: 'Montserrat',
fontSize: 15.0)),
InkWell(
onTap: () {},
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
color: Colors.white),
child: Center(
child: Icon(
Icons.add,
color: Color(0xFF7A9BEE),
size: 20.0,
),
),
),
)
],
),
)
],
),
SizedBox(height: 20.0),
Container(
height: 150.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
_buildInfoCard('WEIGHT', '300', 'G'),
SizedBox(width: 10.0),
_buildInfoCard('CALORIES', '267', 'CAL'),
SizedBox(width: 10.0),
_buildInfoCard('VITAMINS', 'A, B6', 'VIT'),
SizedBox(width: 10.0),
_buildInfoCard('AVAIL', 'NO', 'AV')
],
)
),
SizedBox(height: 20.0),
Padding(
padding: EdgeInsets.only(bottom:5.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(10.0), topRight: Radius.circular(10.0), bottomLeft: Radius.circular(25.0), bottomRight: Radius.circular(25.0)),
color: Colors.black
),
height: 50.0,
child: Center(
child: Text(
'\$52.00',
style: TextStyle(
color: Colors.white,
fontFamily: 'Montserrat'
)
),
),
),
)
],
))
])
]));
}
Widget _buildInfoCard(String cardTitle, String info, String unit) {
return InkWell(
onTap: () {
selectCard(cardTitle);
},
child: AnimatedContainer(
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: cardTitle == selectedCard ? Color(0xFF7A9BEE) : Colors.white,
border: Border.all(
color: cardTitle == selectedCard ?
Colors.transparent :
Colors.grey.withOpacity(0.3),
style: BorderStyle.solid,
width: 0.75
),
),
height: 100.0,
width: 100.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 8.0, left: 15.0),
child: Text(cardTitle,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
color:
cardTitle == selectedCard ? Colors.white : Colors.grey.withOpacity(0.7),
)),
),
Padding(
padding: const EdgeInsets.only(left: 15.0, bottom: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(info,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 14.0,
color: cardTitle == selectedCard
? Colors.white
: Colors.black,
fontWeight: FontWeight.bold)),
Text(unit,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
color: cardTitle == selectedCard
? Colors.white
: Colors.black,
))
],
),
)
]
)
)
);
}
selectCard(cardTitle) {
setState(() {
selectedCard = cardTitle;
});
}
}
Solved, for some reason I didn't have my Flutter SDK path specified:
1.) Go to Settings
2.) Search Flutter
3.) Click Flutter under Languages & Frameworks
4.) Add you Flutter directory to path, in my case C:\flutter
5.) Apply & OK, Restart IDE

Flutter Card Layout

So I'm new to flutter, and I'm trying to make a card. But I can't seem to get my desired output.
I tried to separate the different widgets, by using rows and columns, but I kept messing it up.
This is my target output
Target output
This is my current progressCurrent progress
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildhomePageAppBar(),
body: buildExhibitorBody(),
);
}
Widget buildExhibitorBody() {
return Container(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
buildExhibitorText(),
SizedBox(
height: 10,
),
buildExhibitorCards(),
SizedBox(height: 10),
],
),
),
);
}
Widget buildhomePageAppBar() {
double profileDimension = 35;
return AppBar(
backgroundColor: Colors.white,
titleSpacing: 0,
title: Padding(
padding: EdgeInsets.only(
left: 20,
),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(
top: 5,
bottom: 5,
),
child: Image(
image: AssetImage('assets/images/plain_logo.png'),
height: 30,
),
),
SizedBox(width: 5),
Text(
'Virtex',
style: TextStyle(
color: Colors.black87,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
)
],
),
),
actions: [
Padding(
padding: EdgeInsets.only(
top: 10,
bottom: 10,
),
child: Container(
height: profileDimension,
width: profileDimension,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.black54,
width: 2,
),
borderRadius: BorderRadius.circular(50),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image(
width: profileDimension,
height: profileDimension,
image: AssetImage(
'assets/images/profile-image.jpeg',
),
fit: BoxFit.cover,
),
),
),
),
SizedBox(width: 20),
],
);
}
Widget buildExhibitorText() {
return Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 20,
bottom: 10,
),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Text(
"Exhibitors",
textAlign: TextAlign.justify,
style: TextStyle(
fontFamily: "DMSans",
letterSpacing: -0.2,
fontSize: 20.0,
color: Colors.black,
fontWeight: FontWeight.w400,
),
),
),
],
),
),
);
}
Widget buildExhibitorCards() { // I think my problem is I don't know how to do the layout here
return Container(
width: 400,
height: 150,
child: Column(children: <Widget>[
Card(
elevation: 1,
child: Padding(
padding: const EdgeInsets.only(),
child: Row(children: [
buildCardImage(),
buildCardExhibitor(),
buildCardIndustry(),
buildCardGo(),
])),
),
]),
);
}
Widget buildCardExhibitor() {
return Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Container(
padding: EdgeInsets.all(10),
width: 40,
height: 40,
child: Center(
child: Row(
children: <Widget>[
Text(
"EN",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
Text('Exhibitor Name')
],
),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(200),
),
color: Colors.red,
),
),
]);
}
Widget buildCardImage() {
return Container(
height: 100,
width: 100,
child: Image(
image: AssetImage('assets/images/onboarding-2.jpg'),
height: 100,
),
);
}
Widget buildCardIndustry() {
return Padding(
padding: EdgeInsets.only(
left: 40,
right: 40,
),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
"Industry 1",
style: TextStyle(
fontFamily: "DMSans",
color: Colors.grey,
letterSpacing: 0.3,
fontSize: 12,
),
),
Text(
"Industry 2",
style: TextStyle(
fontFamily: "DMSans",
letterSpacing: -0.3,
fontSize: 12,
color: Colors.grey,
fontWeight: FontWeight.w500,
),
),
],
),
),
);
}
Widget buildCardGo() {
return Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Text(
'Go to Booth',
style: TextStyle(
color: Colors.blue,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(width: 5),
IconButton(
icon: Icon(
MdiIcons.fromString('arrow-right'),
size: 30,
color: Colors.black,
),
onPressed: () {
Navigator.of(context).pop();
},
),
]);
}
}
I would greatly appreciate any kind of help.
Look:
My own Code
import 'package:flutter/material.dart';
class CardLayout extends StatelessWidget {
Widget buildCardImage = Container(
margin: EdgeInsets.only(right: 10.0),
width: 150,
height: 150,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage("https://picsum.photos/250?image=9"),
),
),
);
Widget buildCardExhibitor =
Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Container(
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(200),
),
color: Colors.red,
),
child: Text(
"EN",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
SizedBox(
width: 10.0,
),
Text(
'Exhibitor Name',
style: TextStyle(
fontSize: 15.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
]);
Widget buildCardIndustry = Padding(
padding: EdgeInsets.all(8.0),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding:
EdgeInsets.only(left: 10.0, right: 10.0, top: 5, bottom: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(100),
),
color: Colors.blueGrey.shade400,
),
child: Text(
'Industry 1',
style: TextStyle(
fontFamily: "DMSans",
color: Colors.white,
letterSpacing: 0.3,
fontSize: 12,
),
),
),
SizedBox(
width: 10.0,
),
Container(
padding:
EdgeInsets.only(left: 10.0, right: 10.0, top: 5, bottom: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(100),
),
color: Colors.blueGrey.shade400,
),
child: Text(
'Industry 2',
style: TextStyle(
fontFamily: "DMSans",
color: Colors.white,
letterSpacing: 0.3,
fontSize: 12,
),
),
),
],
),
),
);
Widget buildCardGo = Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Text(
'Go to Booth',
style: TextStyle(
color: Colors.blue,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(width: 3),
IconButton(
icon: Icon(
Icons.arrow_forward_rounded,
size: 30,
color: Colors.blue,
),
onPressed: () {
//Navigator.pop(context);
},
),
]);
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text('Exhibitor'),
actions: [
IconButton(
icon: Icon(Icons.filter_list_rounded),
onPressed: () {
Navigator.pop(context);
})
],
),
body: Container(
margin: EdgeInsets.only(top: 10.0),
width: MediaQuery.of(context).size.width,
//height: 150.0, // remove this line -------------- (1) [EDIT]
child: Column(
// wrap card with column and add listtile as children -------------- (2) [EDIT]
children: [
ListTile(
leading: Text('Exhibitor'),
trailing: IconButton(
icon: Icon(Icons.filter_list_rounded),
onPressed: () {
Navigator.pop(context);
}),
),
Card(
elevation: 5.0,
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(5.0),
child: Row(
children: <Widget>[
buildCardImage,
Expanded(
child: Column(
children: <Widget>[
buildCardExhibitor,
buildCardIndustry,
buildCardGo
],
))
],
),
),
),
],
),
),
));
}
}

ListView isn't scrolling in Flutter

ListView is not working here, Firstly instead of padding I used Positioned() but there is a similar issue on github and there I got to know that scrollable widget shouldn't be placed inside Positioned() so i replaced it with Padding(), but got no success.
here is my code
import 'package:flutter/material.dart';
import 'package:cpblog/webview.dart';
import 'package:flutter/rendering.dart';
class DetailsPage extends StatefulWidget {
final heroTag;
final foodName;
final url;
final text;
DetailsPage({this.heroTag, this.foodName,this.url,this.text});
#override
_DetailsPageState createState() => _DetailsPageState();
}
class _DetailsPageState extends State<DetailsPage> {
var selectedCard = 'WEIGHT';
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF7A9BEE),
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(Icons.arrow_back_ios),
color: Colors.white,
),
backgroundColor: Colors.transparent,
elevation: 0.0,
title: Text('Here You Go!!',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 18.0,
color: Colors.white)),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.more_horiz),
onPressed: () {},
color: Colors.white,
)
],
),
body: ListView(children: [
Stack(children: [
Container(
height: MediaQuery.of(context).size.height - 82.0,
width: MediaQuery.of(context).size.width,
color: Colors.transparent),
Padding(
padding: const EdgeInsets.only(top: 75.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(45.0),
topRight: Radius.circular(45.0),
),
color: Colors.white),
height: MediaQuery.of(context).size.height - 100.0,
width: MediaQuery.of(context).size.width),
),
Padding(
padding: EdgeInsets.only(top: 30.0,
left: (MediaQuery.of(context).size.width / 2) - 100.0,),
child: Hero(
tag: widget.heroTag,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(widget.heroTag),
fit: BoxFit.cover)),
height: 200.0,
width: 200.0)),
),
Padding(
padding: const EdgeInsets.only(top:250.0,right:25.0,left: 25.0),
child: ListView(
shrinkWrap: true,
children: <Widget>[
Text(widget.foodName,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 22.0,
fontWeight: FontWeight.bold)),
SizedBox(height: 20.0),
Text(widget.text,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 20.0,
)),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 125.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(17.0),
color: Color(0xFF7A9BEE)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => WebView(widget.url, widget.foodName)));
},
child:Text('View More',
style: TextStyle(
color: Colors.white,
fontFamily: 'Montserrat',
fontSize: 15.0)),
)
],
),
)
],
),
SizedBox(height: 20.0),
Container(
height: 150.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
_buildInfoCard('WEIGHT', '300', 'G'),
SizedBox(width: 10.0),
_buildInfoCard('CALORIES', '267', 'CAL'),
SizedBox(width: 10.0),
_buildInfoCard('VITAMINS', 'A, B6', 'VIT'),
SizedBox(width: 10.0),
_buildInfoCard('AVAIL', 'NO', 'AV')
],
)
),
SizedBox(height: 20.0),
Padding(
padding: EdgeInsets.only(bottom:5.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(10.0), topRight: Radius.circular(10.0), bottomLeft: Radius.circular(25.0), bottomRight: Radius.circular(25.0)),
color: Colors.black
),
height: 50.0,
child:
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Center(
child: Text(
'Back',
style: TextStyle(
color: Colors.white,
fontFamily: 'Montserrat'
)
),
),
)
),
)
],
),
)
])
]));
}
Widget _buildInfoCard(String cardTitle, String info, String unit) {
return InkWell(
onTap: () {
selectCard(cardTitle);
},
child: AnimatedContainer(
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: cardTitle == selectedCard ? Color(0xFF7A9BEE) : Colors.white,
border: Border.all(
color: cardTitle == selectedCard ?
Colors.transparent :
Colors.grey.withOpacity(0.3),
style: BorderStyle.solid,
width: 0.75
),
),
height: 100.0,
width: 100.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 8.0, left: 15.0),
child: Text(cardTitle,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
color:
cardTitle == selectedCard ? Colors.white : Colors.grey.withOpacity(0.7),
)),
),
Padding(
padding: const EdgeInsets.only(left: 15.0, bottom: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(info,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 14.0,
color: cardTitle == selectedCard
? Colors.white
: Colors.black,
fontWeight: FontWeight.bold)),
Text(unit,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
color: cardTitle == selectedCard
? Colors.white
: Colors.black,
))
],
),
)
]
)
)
);
}
selectCard(cardTitle) {
setState(() {
selectedCard = cardTitle;
});
}
}
I tried physics, listView.builder(),but everytime I get the same result.
Thank you in advance!!!!
Surround you ListView with Expanded widget.
You can't have a scrollable widget inside another scrollable widget without setting a proper height for the inner one. Or use ConstrainedBox

Flutter - type 'BoxDecoration' is not a subtype of type 'Widget'

FutureBuilder(
//UserData from DB
future: getUserData(),
builder: (BuildContext context, AsyncSnapshot<FirebaseUser> snapshot) {
if (snapshot.hasData) {
return new Column(
children: <Widget>[
Container(
height: 200.0,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFF051622), Color(0xFF1BA098)],
),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(15.0),
bottomRight: Radius.circular(15.0),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(top: 18.0, left: 12.0),
child: GestureDetector(
child: CircleAvatar(
radius: 30.0,
backgroundColor: Colors.white,
child: (_imageFile != null)
? BoxDecoration(///This is where error happens
shape: BoxShape.circle,
image: DecorationImage(
image: FileImage(_imageFile),
fit: BoxFit.fill),
)
: Icon(Icons.add_a_photo),//Replace with Image From DB
),
onTap: () {
_getImage();
},
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 75.0, top: 20.0),
child: TextField(
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xFF1BA098),
),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xFFDEB992),
),
),
hintText:
"${snapshot.data.displayName}", //Name comes from db as displayName
hintStyle: TextStyle(
color: Colors.white, fontSize: 18.0),
),
style: TextStyle(
color: Colors.white, fontSize: 18.0),
controller: newName,
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 12.0, left: 20.0),
child: Text(
"${snapshot.data.email}", //Email from DB as email
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.only(top: 7.0, left: 18.0),
child: Text(
"${snapshot.data.phoneNumber}", //Number from DB as phoneNumber
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
),
Row(
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(top: 10.0, left: 18.0),
child: Icon(
Icons.star_border,
size: 30.0,
color: Colors.amber,
),
),
Padding(
padding:
const EdgeInsets.only(top: 15.0, left: 2.0),
child: Text(
"0.0", //Rating from db for user
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic),
),
),
Padding(
padding: const EdgeInsets.only(
top: 8.0,
left:
200.0),
child: ArgonTimerButton(
borderRadius: 50.0,
color: Colors.greenAccent,
height: 35.0,
width: 100.0,
child: Text(
"Update",
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.w700,
color: Colors.black,
),
),
loader: (time) {
return Container(
padding: EdgeInsets.all(10.0),
child: SpinKitRing(
color: Color(0xFF1BA098),
lineWidth: 3.0,
size: 20.0,
),
);
},
onTap: (startTimer, btnState) {
startTimer(6);
verifyDetails();
},
),
),
],
),
],
),
),
],
);
}
},
),
The Whole body is on FutureBuilder(To get data from Firebase into snapShot)
And the error is
════════ Exception caught by widgets library ═══════════════════════════════════
type 'BoxDecoration' is not a subtype of type 'Widget'
The relevant error-causing widget was
FutureBuilder
lib\mainScreens\Profile.dart:37
════════════════════════════════════════════════════════════════════════════
Pranavan BoxDecoration isn't a widget wrap it by a Container as follow:
Container(
decoration: BoxDecoration( ///This is where error happens
shape: BoxShape.circle,
image: DecorationImage(
image: FileImage("_imageFile"), fit: BoxFit.fill),
),
),