Overlapping of detail that I want to show in my detail screen - flutter

#override
Widget build(BuildContext context) {
return InkWell(
onTap: ()
{
Navigator.push(context, MaterialPageRoute(builder: (c)=> HistoryDetailScreen(orderID: orderID)));
},
child: FutureBuilder<DocumentSnapshot>(
future: FirebaseFirestore.instance
.collection("orders")
.doc(orderID)
.get(),
builder: (c, snapshot)
{
Map? dataMap;
if(snapshot.hasData)
{
dataMap = snapshot.data!.data()! as Map<String, dynamic>;
totalAmount = dataMap["totalAmount"].toString();
customerName = dataMap["orderBy"].toString();
}
return snapshot.hasData
?
Container(
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 5,),
Text(
"ORDER ID: "+customerName.toString(),
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Acme",
),
),
SizedBox(height: 5),
Text(
"Total Amount: ₱" + totalAmount.toString(),
style: const TextStyle(
fontWeight: FontWeight.w500,
color: Colors.black,
fontSize: 16,
fontFamily: "Acme",
),
),
SizedBox(height: 5,),
Text(
"More Info >>",
style: const TextStyle(
color: Colors.grey,
fontSize: 13,
fontFamily: "Acme",
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white
),
padding: const EdgeInsets.all(5),
margin: const EdgeInsets.all(5),
height: itemCount! * 50,
child: Stack(
children: [
Padding(padding: EdgeInsets.all(10)),
ListView.builder(
itemCount: itemCount,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index)
{
Items model = Items.fromJson(data![index].data()! as Map<String, dynamic>);
return Align(
heightFactor: 0.3,
alignment: Alignment.topCenter,
child: placedOrderDesignWidget(model, context, seperateQuantitiesList![index]),
);
},
),
],
),
),
],
),
)
:Center(child: circularProgress(),);
},
),
);
}
}
Widget placedOrderDesignWidget(Items model, BuildContext context, seperateQuantitiesList)
{
return Container(
width: MediaQuery.of(context).size.width,
height: 110,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 3,
blurRadius: 3,
offset: Offset(0, 3), // changes position of shadow
),
],
),
child: Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10.0), //add border radius
child: Image.network(model.thumbnailUrl!, width: 90, height: 90, fit: BoxFit.cover,),
),
const SizedBox(width: 10.0,),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 10,
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Text(
model.name! + " x " + seperateQuantitiesList,
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Acme",
),
),
),
const SizedBox(
width: 5,
),
],
),
Text(
"₱ " + model.price.toString(),
style: TextStyle(fontSize: 16.0, color: Colors.blue),
),
],
),
),
],
),
),
);
}
I wanted to avoid the overlapping of data that being shown in my screen

Related

Flutterflow RUN and TEST White screen - but shows top bar

I ve been following the exact steps from https://www.youtube.com/watch?v=YjweeM_Bt00
However, when I want to test it in either test or run, it loads only the top bar.
The rest is only white screen.
The preview mode opens correctly but of course doesn't show any data from firebase.
I suspect there is a problem with that but I triple checked every step in there and I just don't know what else to do.
Below is code for home page. any page loads with same problem
Thanks for the help.
import '../backend/backend.dart';
import '../drill_details/drill_details_widget.dart';
import '../flutter_flow/flutter_flow_theme.dart';
import '../flutter_flow/flutter_flow_util.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class HomePageWidget extends StatefulWidget {
const HomePageWidget({Key? key}) : super(key: key);
#override
_HomePageWidgetState createState() => _HomePageWidgetState();
}
class _HomePageWidgetState extends State<HomePageWidget> {
final scaffoldKey = GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
backgroundColor: FlutterFlowTheme.of(context).primaryColor,
automaticallyImplyLeading: false,
title: Text(
'Drills',
style: FlutterFlowTheme.of(context).title2.override(
fontFamily: 'Poppins',
color: Colors.white,
fontSize: 22,
),
),
actions: [],
centerTitle: false,
elevation: 2,
),
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
body: SafeArea(
child: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
StreamBuilder<List<DrillsRecord>>(
stream: queryDrillsRecord(),
builder: (context, snapshot) {
// Customize what your widget looks like when it's loading.
if (!snapshot.hasData) {
return Center(
child: SizedBox(
width: 50,
height: 50,
child: CircularProgressIndicator(
color: FlutterFlowTheme.of(context).primaryColor,
),
),
);
}
List<DrillsRecord> listViewDrillsRecordList =
snapshot.data!;
return ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: listViewDrillsRecordList.length,
itemBuilder: (context, listViewIndex) {
final listViewDrillsRecord =
listViewDrillsRecordList[listViewIndex];
return Padding(
padding:
EdgeInsetsDirectional.fromSTEB(16, 12, 16, 12),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 3,
color: Color(0x3D0F1113),
offset: Offset(0, 1),
)
],
borderRadius: BorderRadius.circular(12),
),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Stack(
children: [
InkWell(
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
DrillDetailsWidget(
docRef: listViewDrillsRecord
.reference,
),
),
);
},
child: ClipRRect(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(0),
bottomRight: Radius.circular(0),
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
child: Image.network(
'https://cdn.dribbble.com/users/5862142/screenshots/18341547/media/4d62994067420d9a295d8f120b4ed097.jpg?compress=1&resize=1200x900&vertical=top',
width: double.infinity,
height: 200,
fit: BoxFit.cover,
),
),
),
Align(
alignment: AlignmentDirectional(1, -1),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
0, 16, 16, 0),
child: InkWell(
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
DrillDetailsWidget(
docRef: listViewDrillsRecord
.reference,
),
),
);
},
child: Container(
width: 70,
height: 32,
decoration: BoxDecoration(
color: Color(0xFF39D2C0),
borderRadius:
BorderRadius.circular(12),
),
alignment:
AlignmentDirectional(0, 0),
child: Padding(
padding: EdgeInsetsDirectional
.fromSTEB(16, 0, 16, 0),
child: Text(
'Open',
style:
FlutterFlowTheme.of(context)
.bodyText1
.override(
fontFamily: 'Outfit',
color: Colors.white,
fontSize: 14,
fontWeight:
FontWeight.normal,
),
),
),
),
),
),
),
],
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
12, 12, 12, 4),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
Text(
listViewDrillsRecord.drillTitle!,
style: FlutterFlowTheme.of(context)
.title3
.override(
fontFamily: 'Outfit',
color: Color(0xFF101213),
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
],
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
12, 0, 12, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Text(
listViewDrillsRecord.coach!,
style: FlutterFlowTheme.of(context)
.bodyText2
.override(
fontFamily: 'Outfit',
color: Color(0xFF57636C),
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
),
],
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
12, 0, 12, 12),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisSize: MainAxisSize.max,
children: [
Icon(
Icons.star_rounded,
color: Color(0xFFEE8B60),
size: 24,
),
Text(
'4.5',
style: FlutterFlowTheme.of(context)
.bodyText2
.override(
fontFamily: 'Outfit',
color: Color(0xFF57636C),
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
],
),
Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.end,
children: [
Text(
listViewDrillsRecord.price!
.toString(),
style: FlutterFlowTheme.of(context)
.title3
.override(
fontFamily: 'Outfit',
color: Color(0xFF101213),
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
Text(
listViewDrillsRecord
.specialtySport!,
style: FlutterFlowTheme.of(context)
.bodyText2
.override(
fontFamily: 'Outfit',
color: Color(0xFF57636C),
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
],
),
],
),
),
],
),
),
);
},
);
},
),
],
),
),
),
),
);
}
}
'''

I can't get data from database with 'for'

I use flutter and firebase but ı cant get multiple data from database help me
hotelekle(
"${hotel5yildiz[0]["foto"]}",
"${hotel5yildiz[0]["adi"]}",
"${hotel5yildiz[0]["puan"]}"),
Padding hotelekle(String resimadres, String hotelad, String puan) {
return Padding(
padding: const EdgeInsets.only(
right: 40,
left: 40,
bottom: 15,
),
child: Container(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
spreadRadius: 3,
blurRadius: 4,
offset: Offset(0, 3),
),
],
borderRadius: BorderRadius.circular(40),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(40),
child: Image.network(
"$resimadres",
width: 300,
height: 150,
),
),
),
),
Padding(
padding: const EdgeInsets.only(right: 35, left: 40, bottom: 7),
child: Row(
children: [
Text(
"$hotelad",
style: TextStyle(
color: Color(0xff2C1E40),
fontWeight: FontWeight.bold,
fontSize: 18),
),
],
),
),
Padding(
padding: const EdgeInsets.only(right: 35, left: 45),
child: Row(
children: [
Icon(
Icons.star,
color: Colors.amber,
size: 16,
),
SizedBox(
width: 5,
),
Text(
"$puan",
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
SizedBox(
width: 15,
),
Icon(
Icons.bed,
color: Color(0xff4A9CC9),
size: 22,
),
SizedBox(
width: 5,
),
Text(
"Hotel",
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
],
),
),
],
),
),
);
}
By multiple data, I'm assuming you want to get a list of items from firebase. In that case, you can use StreamBuilder. I am sharing with you a snippet of code and you can adjust based on your needs.
On the widget tree, where you want to render the list of data, add in a StreamBuilder
Expanded(
child: StreamBuilder<dynamic?>(
stream: FirebaseFirestore.instance.collection('collection').snapshots();,
builder:(context, snapshot) {
if(snapshot.hasError){
return Text(snapshot.error.toString());
} else if(snapshot.hasData){
final List sd = [];
snapshot.data!.docs.map((DocumentSnapshot doc) {
Map m = doc.data() as Map<String, dynamic>;
sd.add(m);
}).toList();
return ListView.builder(
itemCount: sd.length,
itemBuilder: (BuildContext context, int index){
return Item(name: sd[index]['attribute1'], text: sd[index]['attribute2'],);
},
);
} else {
return Center(child: CircularProgressIndicator(),);
}
},
)
)
If you have any further queries, let me know and I'll make sure to get back to you.

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

Data Types in Flutter

Hi guys so I am working around a datatype that is "int" and "double"... but how do I pass it in the text such that I can have a parenthesis or bracket around my int like this; (260) and a currency or letters attached to my double like this; $20.00 or GHS15.00
any help
this is my code;
class FoodDetails {
final Color primaryColor, backColor;
final double width, productRate, productPrice;
final String productUrl, productName;
FoodDetails({
this.primaryColor,
this.backColor,
this.width,
this.productRate,
this.productUrl,
this.productName,
this.productPrice,
});
}
List<FoodDetails> demoFoods = [
FoodDetails(
productName: 'Burger + Fries',
productPrice: 20.00,
productRate: 3.5,
productUrl: 'assets/images/kfc1.png',
backColor: Colors.orange.shade600,
),
FoodDetails(
productName: 'Peperoni Pizza',
productPrice: 45.00,
productRate: 3.5,
productUrl: 'assets/images/pizza2.png',
backColor: Colors.orangeAccent.shade100,
),
FoodDetails(
productName: 'Sundae IceCream',
productPrice: 40.00,
productRate: 5.0,
productUrl: 'assets/images/regularsundae.png',
backColor: Colors.purple,
),
FoodDetails(
productName: 'Chicken Nuggets 2pcs.',
productPrice: 35.05,
productRate: 3.6,
productUrl: 'assets/images/kfc2.png',
backColor: Colors.amber.shade50,
),
];
this is where I am passing the datatypes just read and follow;
class FoodCard extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SizedBox(
width: SizeConfig.screenWidth,
height: getProportionateScreenHeight(220),
child: Column(
children: [
Expanded(
flex: 3,
child: PageView.builder(
onPageChanged: (value) {},
controller: PageController(
initialPage: 0,
),
itemCount: demoFoods.length,
itemBuilder: (context, index) => Container(
margin: EdgeInsets.only(right: 10),
width: SizeConfig.screenWidth,
decoration: BoxDecoration(
color: demoFoods[index].backColor,
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: AssetImage(demoFoods[index].productUrl),
fit: BoxFit.cover,
),
boxShadow: [
BoxShadow(
color: Colors.white70,
blurRadius: 4.0,
offset: Offset(3.0, 3.0),
),
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: double.infinity,
height: 70,
padding: EdgeInsets.symmetric(
horizontal: getProportionateScreenWidth(10),
vertical: getProportionateScreenHeight(5),
),
decoration: cardInfoDecoration,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
demoFoods[index].productName,
style: TextStyle(
color: CupertinoColors.white,
fontSize: 20,
fontWeight: FontWeight.w700),
),
Spacer(),
Container(
padding: const EdgeInsets.all(4.0),
decoration: likedWidgetDecoration,
child: Icon(
Icons.near_me,
size: 17.0,
color: kPrimaryColor,
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Row(
children: <Widget>[
Text(
demoFoods[index].productRate.toString(),
style: TextStyle(
fontSize: 17.5,
color: Colors.white,
),
),
SizedBox(
width: getProportionateScreenWidth(10)),
buildSmoothStarRating(index),
Spacer(),
Text(
demoFoods[index].productPrice.toString(),
style: TextStyle(
fontSize: 17.5,
),
),
],
),
),
],
),
),
],
),
),
),
),
],
),
);
}
You mean something like this?
var myInt = 42;
Text('\$$myInt ') // $42
Text('\$($myInt) ') // $(42)
Text('GHS$myInt ') // GHS42

Flutter StaggeredGridView.countBuilder scrollcontroll. I am having this error( type 'String' is not a subtype of type 'int' of 'index')

I am having problem when I used the scrollcontroller to controll the gridview. I am having the error ( type 'String' is not a subtype of type 'int' of 'index'). But it was perfectly working before using the scrollcontroller. I don't where i need to change in order to remove this error. I also check the other issues regarding this in stackoverflow but couldn't get it. Can anyone check and tell me what can be change here in order to remove the error and show the data and also if my condition is right for loading 10 data in every scroll end.
import 'dart:convert';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:gridview_screoll/grid_content.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'constant.dart';
class ScrollableGrid extends StatefulWidget {
#override
_ScrollableGridState createState() => _ScrollableGridState();
}
class _ScrollableGridState extends State<ScrollableGrid> {
List data = [];
bool isLoading = false;
ScrollController _scrollController;
int pageCount = 1;
#override
void initState() {
// TODO: implement initState
super.initState();
this.fetchTopProducts();
addItemIntoLisT(pageCount);
_scrollController = new ScrollController(initialScrollOffset: 5.0)
..addListener(_scrollListener);
}
_scrollListener() {
if (_scrollController.offset >=
_scrollController.position.maxScrollExtent &&
!_scrollController.position.outOfRange) {
setState(() {
isLoading = true;
if (isLoading) {
pageCount = pageCount + 1;
addItemIntoLisT(pageCount);
}
});
}
}
void addItemIntoLisT(var pageCount) {
for (int i = (pageCount * 10) - 10; i < pageCount * 10; i++) {
fetchTopProducts();
isLoading = false;
}
}
#override
void dispose() {
_scrollController.dispose();
super.dispose();
}
fetchTopProducts() async {
setState(() {
isLoading = true;
});
var url = base_api + "api_frontend/top_products";
var response = await http.get(url);
print(response.body);
if (response.statusCode == 200) {
setState(() {
data.add(json.decode(response.body)['top_products']);
isLoading = false;
});
} else {
setState(() {
data = [];
isLoading = false;
});
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.1,
backgroundColor: Colors.indigo,
title: Text('GridControll'),
//backgroundColor: Color.fromRGBO(244, 246, 249, 1),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height * 88/100,
color: Color.fromRGBO(244, 246, 249, 1),
margin: const EdgeInsets.only(
left: 0.0, bottom: 2.0, right: 0.0, top: 0),
child: getBody2(),
),
],
),
),
);
}
Widget getBody2() {
if (isLoading || data.length == 0) {
return Center(
child: CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(primary)));
}
return StaggeredGridView.countBuilder(
padding: const EdgeInsets.all(10.0),
controller: _scrollController,
shrinkWrap: true,
// physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
itemCount: data.length - 1,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
//builder: (context) => ProductDetails(item: data2[index]),
builder: (context) => productDetail(data[index]),
),
);
},
child: cardItem2(data[index]));
},
staggeredTileBuilder: (int index) => StaggeredTile.fit(1),
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
);
}
}
Here is grid_content.dart:
import 'package:html_unescape/html_unescape.dart';
import 'package:flutter/material.dart';
Widget cardItem2(item) {
// var img = item['thumbnail'];
// var thumbnail = base_api+"uploads/product_thumbnails/"+img;
var productId = item['product_id'];
var thumbnail = item['thumbnail'];
var unescape = new HtmlUnescape();
var name = unescape.convert(item['name']);
var unit = item['unit'];
var discount = item['discount'];
var price = item['price'];
var discountPrice = item['discount_price'];
return discount != '0%' ? Card(
elevation: 6,
shadowColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(9.0)),
child: Stack(
fit: StackFit.loose,
alignment: Alignment.center,
children: [
Column(
children: <Widget>[
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.only(topRight: Radius.circular(9), topLeft: Radius.circular(9)),
child: FadeInImage.assetNetwork(
placeholder: 'assets/loading_animated.gif',
image: thumbnail,
height: 110,
width: double.infinity,
fit: BoxFit.cover,
),
),
],
),
Padding(
padding: const EdgeInsets.only(left:6.0, right: 6.0),
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: TextStyle(
fontSize: 16.0,
color: Colors.black87,
fontWeight: FontWeight.w100,
),
),
Text(
unit,
style: TextStyle(
fontSize: 12.0,
color: Colors.black45,
fontWeight: FontWeight.w100,
),
),
Row(
children: [
Expanded(
flex: 2,
child: Text(
discountPrice,
style: TextStyle(
fontSize: 16.0,
color: Colors.green,
fontWeight: FontWeight.w500,
),
),
),
Expanded(
flex: 2,
child: Text(
price,
style: TextStyle(
fontSize: 12.0,
color: Colors.black38,
fontWeight: FontWeight.w500,
decoration: TextDecoration.lineThrough,
),
),
),
ButtonTheme(
padding: EdgeInsets.symmetric(vertical: 4.0, horizontal: 6.0), //adds padding inside the button
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, //limits the touch area to the button area
minWidth: 0, //wraps child's width
height: 25,
child: FlatButton(
minWidth: 5,
height: 40,
color: Color.fromRGBO(100, 186, 2, 1),
onPressed: () {
},
child: Icon(Icons.shopping_cart, color: Colors.white,),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
side: BorderSide(color: Color.fromRGBO(100, 186, 2, 1),)),
),
),
],
),
],
),
),
),
],
),
),
],
),
],
),
) : Card(
elevation: 6,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(9.0)),
child: Stack(
fit: StackFit.loose,
alignment: Alignment.center,
children: [
Column(
children: <Widget>[
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.only(topRight: Radius.circular(9), topLeft: Radius.circular(9)),
child: FadeInImage.assetNetwork(
placeholder: 'assets/loading_animated.gif',
image: thumbnail,
height: 110,
width: double.infinity,
fit: BoxFit.cover,
),
),
],
),
Padding(
padding: const EdgeInsets.only(left:6.0, right: 6.0),
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: TextStyle(
fontSize: 16.0,
color: Colors.black87,
fontWeight: FontWeight.w100,
),
),
Text(
unit,
style: TextStyle(
fontSize: 12.0,
color: Colors.black45,
fontWeight: FontWeight.w100,
),
),
Row(
children: [
Expanded(
flex: 1,
child: Text(
price,
style: TextStyle(
fontSize: 15.0,
color: Colors.green,
fontWeight: FontWeight.w500,
),
),
),
ButtonTheme(
padding: EdgeInsets.symmetric(vertical: 4.0, horizontal: 6.0),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
minWidth: 0, //wraps child's width
height: 25,
child: FlatButton(
minWidth: 10,
//height: 40,
color: Color.fromRGBO(100, 186, 2, 1),
onPressed: () {
},
child: Icon(Icons.shopping_cart, color: Colors.white,),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
side: BorderSide(color: Color.fromRGBO(100, 186, 2, 1),)),
),
),
],
),
],
),
),
),
],
),
),
],
),
],
),
);
}
productDetail(item) {
// var img = item['thumbnail'];
// var thumbnail = base_api+"uploads/product_thumbnails/"+img;
var productId = item['product_id'];
var thumbnail = item['thumbnail'];
var unescape = new HtmlUnescape();
var name = unescape.convert(item['name']);
var discount = item['discount'];
var price = item['price'];
var disPrice= item['discount_price'];
var unit = item['unit'];
return Scaffold(
appBar: AppBar(
elevation: 0.1,
iconTheme: IconThemeData(color: Colors.white),
backgroundColor: Colors.red,
title: Center(
child: Padding(
padding: const EdgeInsets.only(right: 50),
child: Text(
'Product Details',
style: TextStyle(color: Colors.white),
),
),
),
actions: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 15, right: 25.0),
child: GestureDetector(
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Icon(
Icons.favorite,
),
],
),
onTap: () {},
),
)
],
),
body: SingleChildScrollView(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: FadeInImage.assetNetwork(
placeholder: 'assets/black_circle.gif',
image: thumbnail,
height: 210,
width: 360,
fit: BoxFit.cover,
),
),
),
Center(
child: Card(
color: Colors.white38,
child: Padding(
padding: const EdgeInsets.only(left: 12.0, right: 12, top: 4, bottom: 4),
child: Text(
unit,
style: TextStyle(
fontSize: 11,
color: Colors.black87,
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Center(
child: discount != '0%' ? Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
disPrice,
style: TextStyle(
fontSize: 22,
color: Colors.black87,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
price,
style: TextStyle(
fontSize: 18,
color: Colors.black54,
decoration: TextDecoration.lineThrough,
),
),
),
],
): Text(
price,
style: TextStyle(
fontSize: 22,
color: Colors.black87,
fontWeight: FontWeight.bold),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: Center(
child: Text(
name,
style: TextStyle(
fontSize: 18,
color: Colors.black54,
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Divider(),
),
Container(
child: Center(
child: Text(
'Quantity',
style: TextStyle(color: Colors.black45, fontSize: 15),
),
),
),
Container(
child: Center(
child: Text(
'1',
style: TextStyle(
color: Colors.black,
fontSize: 22,
fontWeight: FontWeight.bold),
),
),
//child: Text(store.activeProduct.qty.toString()),
),
Padding(
padding: const EdgeInsets.only(
left: 100.0, right: 100.0, bottom: 10.0),
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
side: BorderSide(color: Color.fromRGBO(41, 193, 126, 1)),
),
color: Color.fromRGBO(41, 193, 126, 1),
padding: EdgeInsets.only(top: 8, bottom: 8),
child: Center(
child: Text(
'BUY NOW',
style: TextStyle(color: Colors.white, fontSize: 16),
),
),
onPressed: () {
}),
),
Padding(
padding: const EdgeInsets.only(
left: 100.0, right: 100.0, bottom: 10.0),
child: FlatButton(
padding: EdgeInsets.only(top: 8, bottom: 8),
child: Center(
child: Text(
'ADD TO CART',
style: TextStyle(color: Color.fromRGBO(41, 193, 126, 1), fontSize: 16),
),
),
onPressed: () {
}),
),
],
),
),
),
);
}
Here is the json file:
{
"top_products": [
{
"product_id": "63",
"category_id": "59",
"name": "Ice Cream",
"price": "$9",
"discount_price": "$8.91",
"discount": "1%",
"unit": "3 kg",
"thumbnail": "http://192.168.0.105/uploads/product_thumbnails/72908baa78a2db38f678283a2e483903.jpg"
},
{
"product_id": "65",
"category_id": "47",
"name": "Malta",
"price": "$5",
"discount_price": "$4.5",
"discount": "10%",
"unit": "1 kg",
"thumbnail": "http://192.168.0.105/uploads/product_thumbnails/a63dcb5e4f883eb946585d287d25c397.jpg"
},
{},
{},
{},
...
],
"message": "Top hundred products",
"status": 200,
"validity": true
}
======== Exception caught by widgets library =======================================================
The following _TypeError was thrown building:
type 'String' is not a subtype of type 'int' of 'index'
When the exception was thrown, this was the stack:
#0 cardItem2 (package:gridview_screoll/grid_content.dart:7:23)
#1 _ScrollableGridState.getBody2.<anonymous closure> (package:gridview_screoll/scroll_grid.dart:130:20)
#2 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:449:22)
#3 SliverVariableSizeBoxAdaptorElement._build.<anonymous closure> (package:flutter_staggered_grid_view/src/widgets/sliver.dart:144:38)
#4 _HashMap.putIfAbsent (dart:collection-patch/collection_patch.dart:140:29)
...
====================================================================================================
itemCount: data.length - 1,
Change this to this:
itemCount: data.length;