Add transactions page
This commit is contained in:
parent
8674fe2adf
commit
1ef27854a0
4 changed files with 273 additions and 0 deletions
|
@ -43,3 +43,10 @@ Future<dynamic> loginPost({email, password}) async {
|
|||
);
|
||||
return req.statusCode;
|
||||
}
|
||||
|
||||
Future<dynamic> getTransactions() async {
|
||||
String tempKey = 'rTugfHPB7Cd4I1OmsbFCHuJvBSjA2C48WOcMghviohNlNj8IZqazvtwJrdGFHDwp';
|
||||
var req = await Dio().post(host + '/transaction', queryParameters: {'key': tempKey});
|
||||
var res = req.data;
|
||||
return res;
|
||||
}
|
133
lib/components/transaction_box.dart
Normal file
133
lib/components/transaction_box.dart
Normal file
|
@ -0,0 +1,133 @@
|
|||
import 'dart:convert';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:nekoya_flutter/api/api.dart';
|
||||
import 'package:nekoya_flutter/components/transaction_product_box.dart';
|
||||
|
||||
class TransactionBox extends StatefulWidget {
|
||||
const TransactionBox({
|
||||
Key? key,
|
||||
required this.orderId,
|
||||
required this.status,
|
||||
required this.firstName,
|
||||
required this.lastName,
|
||||
required this.phoneNumber,
|
||||
required this.streetAddress1,
|
||||
required this.district,
|
||||
required this.subDistrict,
|
||||
required this.province,
|
||||
required this.region,
|
||||
required this.postalCode,
|
||||
required this.logistic,
|
||||
required this.data
|
||||
}) : super(key: key);
|
||||
|
||||
final int orderId;
|
||||
final String status;
|
||||
final String firstName;
|
||||
final String lastName;
|
||||
final String phoneNumber;
|
||||
final String streetAddress1;
|
||||
final String district;
|
||||
final String subDistrict;
|
||||
final String province;
|
||||
final String region;
|
||||
final String postalCode;
|
||||
final String logistic;
|
||||
final String data;
|
||||
|
||||
@override
|
||||
State<TransactionBox> createState() => _TransactionBoxState();
|
||||
}
|
||||
|
||||
class _TransactionBoxState extends State<TransactionBox> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var orderData = jsonDecode(widget.data);
|
||||
|
||||
return ExpansionTile(
|
||||
backgroundColor: const Color(0xff212226),
|
||||
// trailing: const Text('-', style: TextStyle(color: Colors.white),),
|
||||
iconColor: Colors.white,
|
||||
collapsedIconColor: Colors.white,
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('#' + widget.orderId.toString(), style: const TextStyle(color: Colors.white),),
|
||||
Text(widget.status, style: const TextStyle(color: Colors.white),)
|
||||
],
|
||||
),
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.all(15.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Sender Details', style: TextStyle(color: Colors.white, fontSize: 15, fontWeight: FontWeight.w600),),
|
||||
const SizedBox(height: 5,),
|
||||
Text("${widget.firstName} ${widget.lastName}", style: const TextStyle(color: Colors.white),),
|
||||
Text(widget.phoneNumber, style: const TextStyle(color: Colors.white),),
|
||||
Text("${widget.streetAddress1}, ${widget.district}, ${widget.subDistrict}, ${widget.province}, ${widget.region}, ${widget.postalCode}", style: const TextStyle(color: Colors.white),),
|
||||
]
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
flex: 1,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Text('Logistic', style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w600),),
|
||||
const SizedBox(height: 5,),
|
||||
Text(widget.logistic, style: const TextStyle(color: Colors.white),),
|
||||
const SizedBox(height: 55,)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Container(
|
||||
margin: const EdgeInsets.all(15.0),
|
||||
child: Card(
|
||||
color: const Color(0xff1b1c1e),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.vertical,
|
||||
shrinkWrap: true,
|
||||
itemCount: orderData.length,
|
||||
itemBuilder: (context, index) {
|
||||
return FutureBuilder<dynamic>(
|
||||
future: getProduct(orderData[index]['product_id']),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
var productData = snapshot.data;
|
||||
return TransactionProductBox(
|
||||
imageUrl: 'https://nekoya.moe.team/img/' + productData[0]['IMAGE'],
|
||||
title: productData[0]['TITLE'],
|
||||
quantity: orderData[index]["quantity"],
|
||||
);
|
||||
}
|
||||
|
||||
return const TransactionProductBox(
|
||||
imageUrl: 'https://i.ibb.co/QJFLZC4/La-Darknesss-Portrait.webp',
|
||||
title: 'Loading...',
|
||||
quantity: 0,
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
73
lib/components/transaction_product_box.dart
Normal file
73
lib/components/transaction_product_box.dart
Normal file
|
@ -0,0 +1,73 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
|
||||
class TransactionProductBox extends StatefulWidget {
|
||||
const TransactionProductBox({Key? key, required this.imageUrl, required this.title, required this.quantity}) : super(key: key);
|
||||
|
||||
final String imageUrl;
|
||||
final String title;
|
||||
final int quantity;
|
||||
|
||||
@override
|
||||
State<TransactionProductBox> createState() => _TransactionProductBoxState();
|
||||
}
|
||||
|
||||
class _TransactionProductBoxState extends State<TransactionProductBox> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 2,
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: widget.imageUrl,
|
||||
placeholder: (context, url) =>
|
||||
const CircularProgressIndicator(
|
||||
color: Color(0xff8B0000),
|
||||
),
|
||||
errorWidget: (context, url, error) =>
|
||||
Image.asset('assets/image-error.webp'),
|
||||
fadeOutDuration: const Duration(milliseconds: 5),
|
||||
imageBuilder: (context, imageProvider) => Container(
|
||||
width: 300,
|
||||
height: 150,
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: imageProvider, fit: BoxFit.cover)),
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 10.0, right: 10.0),
|
||||
child: Text(
|
||||
widget.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600),
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10,),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 10.0, right: 10.0),
|
||||
child: Text("Quantity : ${widget.quantity.toString()}",
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w400
|
||||
)
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
60
lib/screens/transactions.dart
Normal file
60
lib/screens/transactions.dart
Normal file
|
@ -0,0 +1,60 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:nekoya_flutter/api/api.dart';
|
||||
import 'package:nekoya_flutter/components/transaction_box.dart';
|
||||
|
||||
class Transactions extends StatefulWidget {
|
||||
const Transactions({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Transactions> createState() => _TransactionsState();
|
||||
}
|
||||
|
||||
class _TransactionsState extends State<Transactions> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xff1b1c1e),
|
||||
appBar: AppBar(
|
||||
title: const Text('Transactions'),
|
||||
centerTitle: true,
|
||||
backgroundColor: const Color(0xff212226),
|
||||
),
|
||||
body: FutureBuilder<dynamic>(
|
||||
future: getTransactions(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
var data = snapshot.data;
|
||||
return ListView.builder(
|
||||
itemCount: data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
return TransactionBox(
|
||||
orderId: data[index]['id'],
|
||||
status: data[index]['status'],
|
||||
firstName: data[index]['firstName'],
|
||||
lastName: data[index]['lastName'],
|
||||
phoneNumber: data[index]['phoneNumber'],
|
||||
streetAddress1: data[index]['streetAddress1'],
|
||||
district: data[index]['district'],
|
||||
subDistrict: data[index]['subDistrict'],
|
||||
province: data[index]['province'],
|
||||
region: data[index]['region'],
|
||||
postalCode: data[index]['postalCode'],
|
||||
logistic: data[index]['logistic'],
|
||||
data: data[index]['data'],
|
||||
);
|
||||
// return Text(data[index]['firstName'] + ' ' + data[index]['lastName'], style: const TextStyle(color: Colors.white),);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Color(0xff8B0000),
|
||||
),
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue