You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/final_products_page.dart

553 lines
33 KiB
Dart

import 'package:diplomaticquarterapp/core/viewModels/pharmacy_categorise_view_model.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/product_detail.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/StarRating.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_pharmacy_widget.dart';
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'base/base_view.dart';
class FinalProductsPage extends StatefulWidget {
final String id;
final int productType; // 1 : default, 2 : manufacturer , 3 : recently viewed
FinalProductsPage({this.id, this.productType = 1});
@override
_FinalProductsPageState createState() => _FinalProductsPageState(id: id);
}
class _FinalProductsPageState extends State<FinalProductsPage> {
String id;
_FinalProductsPageState({this.id});
String categoriseName = "Personal Care";
bool styleOne = true;
bool styleTwo = false;
Icon styleIcon = Icon(
Icons.widgets_sharp,
color: Colors.blue,
size: 29.0,
);
@override
Widget build(BuildContext context) {
return BaseView<PharmacyCategoriseViewModel>(
onModelReady: (model) {
if (widget.productType == 1) {
model.getFinalProducts(i: id);
} else if (widget.productType == 2) {
model.getManufacturerProducts(id);
} else if (widget.productType == 3) {
model.getLastVisitedProducts();
} else {
model.getBestSellerProducts();
}
},
allowAny: true,
builder: (BuildContext context, PharmacyCategoriseViewModel model,
Widget child) =>
PharmacyAppScaffold(
appBarTitle: "Products",
isBottomBar: false,
isShowAppBar: true,
backgroundColor: Colors.white,
isShowDecPage: false,
baseViewModel: model,
body: Container(
height: MediaQuery.of(context).size.height * 5.87,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//Expanded widget heree if nassery
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: EdgeInsets.all(8.0),
child: Texts(
'Products',
fontWeight: FontWeight.w600,
),
),
Row(
children: [
Container(
height: 44.0,
child: VerticalDivider(
color: Colors.black45,
thickness: 1.0,
//width: 0.3,
// indent: 0.0,
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: InkWell(
child: styleIcon,
onTap: () {
setState(() {
if (styleOne == true) {
styleOne = false;
styleTwo = true;
styleIcon = Icon(
Icons.auto_awesome_mosaic,
color: Colors.blue,
size: 29.0,
);
} else {
styleOne = true;
styleTwo = false;
styleIcon = Icon(
Icons.widgets_sharp,
color: Colors.blue,
size: 29.0,
);
}
});
},
),
),
],
),
],
),
Divider(
thickness: 1.0,
color: Colors.grey.shade400,
),
styleOne == true
? Expanded(
child: Container(
height: MediaQuery.of(context).size.height * 3.90,
child: GridView.builder(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 0.5,
mainAxisSpacing: 2.0,
childAspectRatio: 1.0,
),
itemCount: model.finalProducts.length,
itemBuilder: (BuildContext context, int index) {
return NetworkBaseView(
baseViewModel: model,
child: InkWell(
child: Card(
color: model.finalProducts[index]
.discountName !=
null
? Color(0xffFFFF00)
: Colors.white,
elevation: 0,
shape: Border(
right: BorderSide(
color: Colors.grey.shade300,
width: 1,
),
left: BorderSide(
color: Colors.grey.shade300,
width: 1,
),
bottom: BorderSide(
color: Colors.grey.shade300,
width: 1,
),
top: BorderSide(
color: Colors.grey.shade300,
width: 1,
),
),
margin: EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(110.0),
),
color: Colors.white,
),
padding: EdgeInsets.symmetric(
horizontal: 0),
width: MediaQuery.of(context)
.size
.width /
3,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Stack(
children: [
Container(
margin:
EdgeInsets.fromLTRB(
0, 16, 0, 0),
alignment:
Alignment.center,
child: Image.network(
model
.finalProducts[
index]
.images
.isNotEmpty
? model
.finalProducts[
index]
.images[0]
.thumb
: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/No_image_3x4.svg/1200px-No_image_3x4.svg.png',
fit: BoxFit.cover,
height: 80,
),
),
Container(
width: model
.finalProducts[
index]
.rxMessage !=
null
? MediaQuery.of(
context)
.size
.width /
2.8
: 0,
padding:
EdgeInsets.all(4),
decoration: BoxDecoration(
color:
Color(0xffb23838),
borderRadius:
BorderRadius.only(
topLeft: Radius
.circular(
6)),
),
child: Texts(
model
.finalProducts[
index]
.rxMessage !=
null
? model
.finalProducts[
index]
.rxMessage
: "",
color: Colors.white,
regular: true,
fontSize: 10,
fontWeight:
FontWeight.w600,
),
),
],
),
Container(
margin: EdgeInsets.symmetric(
horizontal: 6,
vertical: 0,
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
if (model
.finalProducts[
index]
.discountName !=
null)
Container(
width:
double.infinity,
height: 13.0,
decoration:
BoxDecoration(
color: Color(
0xff5AB145),
),
child: Center(
child: Texts(
model
.finalProducts[
index]
.discountName,
regular: true,
color:
Colors.white,
fontSize: 10.4,
),
),
),
Texts(
model
.finalProducts[
index]
.name,
regular: true,
fontSize: 12,
fontWeight:
FontWeight.w400,
),
Padding(
padding:
const EdgeInsets
.only(
top: 4,
bottom: 4),
child: Texts(
"SAR ${model.finalProducts[index].price}",
bold: true,
fontSize: 14,
),
),
Row(
children: [
StarRating(
totalAverage: model
.finalProducts[
index]
.approvedRatingSum >
0
? (model.finalProducts[index].approvedRatingSum
.toDouble() /
model
.finalProducts[index]
.approvedRatingSum
.toDouble())
.toDouble()
: 0,
forceStars: true),
Texts(
"(${model.finalProducts[index].approvedTotalReviews})",
regular: true,
fontSize: 10,
fontWeight:
FontWeight.w400,
)
],
),
],
),
),
],
),
),
),
onTap: () => {
Navigator.push(
context,
FadePage(
page: ProductDetailPage(
model.finalProducts[index]),
)),
},
));
},
),
),
)
: Expanded(
child: Container(
height: MediaQuery.of(context).size.height * 5.0,
child: ListView.builder(
itemCount: model.finalProducts.length,
itemBuilder:
(BuildContext context, int index) {
return InkWell(
child: Card(
child: Row(
children: [
Stack(
children: [
Column(
children: [
Container(
decoration:
BoxDecoration(),
child: Padding(
padding:
EdgeInsets.only(
left: 9.0,
top: 8.0,
right: 10.0,
),
),
),
Container(
margin:
EdgeInsets.fromLTRB(
0, 0, 0, 0),
alignment:
Alignment.center,
child: Image.network(
model
.finalProducts[
index]
.images
.isNotEmpty
? model
.finalProducts[
index]
.images[0]
.thumb
: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/No_image_3x4.svg/1200px-No_image_3x4.svg.png',
fit: BoxFit.contain,
height: 80,
),
),
],
),
Column(
children: [
Container(
width: model
.finalProducts[
index]
.rxMessage !=
null
? MediaQuery.of(
context)
.size
.width /
3.5
: 0,
padding:
EdgeInsets.all(4),
decoration: BoxDecoration(
color:
Color(0xffb23838),
borderRadius:
BorderRadius.only(
topLeft: Radius
.circular(
6)),
),
child: Texts(
model
.finalProducts[
index]
.rxMessage !=
null
? model
.finalProducts[
index]
.rxMessage
: "",
color: Colors.white,
regular: true,
fontSize: 10,
fontWeight:
FontWeight.w600,
),
),
],
),
],
),
Container(
height: 100.0,
margin: EdgeInsets.symmetric(
horizontal: 6,
vertical: 0,
),
child: Column(
mainAxisAlignment:
MainAxisAlignment
.spaceAround,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
SizedBox(
height: 4.0,
),
Container(
width:
MediaQuery.of(context)
.size
.width *
0.65,
child: Texts(
model.finalProducts[index]
.name,
regular: true,
fontSize: 13.2,
fontWeight:
FontWeight.w500,
maxLines: 5,
),
),
SizedBox(
height: 8.0,
),
Padding(
padding:
const EdgeInsets.only(
top: 4, bottom: 4),
child: Texts(
"SAR ${model.finalProducts[index].price}",
bold: true,
fontSize: 14,
),
),
Row(
children: [
StarRating(
totalAverage: model
.finalProducts[
index]
.approvedRatingSum >
0
? (model
.finalProducts[
index]
.approvedRatingSum
.toDouble() /
model
.finalProducts[
index]
.approvedRatingSum
.toDouble())
.toDouble()
: 0,
forceStars: true),
Texts(
"(${model.finalProducts[index].approvedTotalReviews})",
regular: true,
fontSize: 10,
fontWeight:
FontWeight.w400,
)
],
),
],
),
),
],
),
),
onTap: () => {
Navigator.push(
context,
FadePage(
page: ProductDetailPage(
model.finalProducts[index]),
)),
},
);
}),
),
)
],
),
),
));
}
}