Commit b4fd1762 by liubohua

1

parent 523509f1
/*
* @Author: lbh
* @Date: 2022-04-09 15:37:41
* @LastEditors: lbh
* @LastEditTime: 2022-04-13 16:28:09
* @Description: file content
*/
import 'package:flutter/material.dart';
import 'package:flutter_one/base/GlobalConfig.dart';
class orderDetail extends StatelessWidget {
const orderDetail({Key? key}) : super(key: key);
static const String routeName = "/orderDetail";
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('訂單詳情'),
titleTextStyle: const TextStyle(
fontSize: 16.0,
color: Colors.white,
),
centerTitle: true,
backgroundColor: GlobalConfig.themeColor,
toolbarHeight: 46.0,
leading: new IconButton(
icon: new Icon(Icons.arrow_back_ios),
onPressed: () => {
Navigator.of(context).pop('刷新'),
},
),
),
),
debugShowCheckedModeBanner: false,
);
}
}
......@@ -2,16 +2,15 @@
* @Author: lbh
* @Date: 2022-04-07 10:07:36
* @LastEditors: lbh
* @LastEditTime: 2022-04-08 20:08:20
* @LastEditTime: 2022-04-13 16:28:24
* @Description: file content
*/
import 'dart:developer';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_one/detail.dart';
import "./base/GlobalConfig.dart";
import 'package:dio/dio.dart';
import 'util/DioManager.dart';
main() {
......@@ -23,8 +22,12 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: HomePage(),
return MaterialApp(
initialRoute: "/",
routes: {
orderDetail.routeName: (context) => orderDetail(),
HomePage.routeName: (context) => HomePage(), //注册首页路由
},
debugShowCheckedModeBanner: false,
);
}
......@@ -32,7 +35,7 @@ class MyApp extends StatelessWidget {
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
static const String routeName = "/";
@override
State<HomePage> createState() => _HomePageState();
}
......@@ -102,15 +105,48 @@ class _ListViewPageState extends State<ListViewPage> {
// 是否还有
bool _hasMore = true;
// 滚动控制器
ScrollController _scrollController = new ScrollController();
@override
void initState() {
super.initState();
this._getData();
// 监听滚动事件
_scrollController.addListener(() {
// 获取滚动条下拉的距离
// print(_scrollController.position.pixels);
// 获取整个页面的高度
// print(_scrollController.position.maxScrollExtent);
if (_scrollController.position.pixels >
_scrollController.position.maxScrollExtent - 40) {
this._getData();
}
});
}
void _getData() async {
if (this._hasMore) {
if (_hasMore) {
// ignore: prefer_collection_literals
Map<String, dynamic> map = Map();
map.addAll({
'brandId': '',
'memberId': 420132,
'pageIndex': 1,
'pageSize': 20,
'restaurantId': 365
});
DioManager.getInstance().get(
'/calendar/otherFunction/getOnlineSpecialGoods', {},
'/ricepon-order/api/orderInfo/getMemberOrderList',
map,
//正常回调
(data) {
setState(() {
//更新UI等
print('打印數據');
print(data);
print('第二條');
print(json.decode(data));
//更新UI等
_list.addAll(json.decode(data)['data']);
});
},
//错误回调
......@@ -130,39 +166,73 @@ class _ListViewPageState extends State<ListViewPage> {
});
}
Widget buildFood(foods) {
List<Widget> tiles = [];
Widget content;
for (var item in foods) {
tiles.add(
Row(
children: [
Text('${item['productName']}'),
Text('x${item['number']}'),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
),
);
}
//重点在这里,因为用编辑器写Column生成的children后面会跟一个<Widget>[],
//此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误,把<Widget>[]删了就可以了
content = Column(children: tiles);
return content;
}
@override
Widget build(BuildContext context) {
return RefreshIndicator(
child: ListView.builder(
itemCount: 10,
itemCount: _list.length,
controller: _scrollController,
// 上拉加载控制器
itemBuilder: (context, index) {
return InkWell(
onTap: () {
log("$index");
print("${_list[index]}");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => orderDetail(),
settings: RouteSettings(
name: "orderDetail",
),
),
);
// Navigator.of(context).pushNamed("orderDetail");
},
child: Container(
margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0),
// color: Colors.white,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(0.0, 1.0), //阴影y轴偏移量
blurRadius: 2.0, //阴影模糊程度
spreadRadius: 0, //阴影扩散程度
),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(0.0, 1.0), //阴影y轴偏移量
blurRadius: 2.0, //阴影模糊程度
spreadRadius: 0, //阴影扩散程度
)
]),
],
),
child: Column(
children: [
ListTile(
// 左邊
leading: Image.network(
'https://hk-ricepon.oss-cn-hongkong.aliyuncs.com/images/member//authority/202204/1648798010297.jpeg',
"${_list[index]['restaurantImg']}",
width: 40.0,
height: 40.0,
fit: BoxFit.cover,
......@@ -171,7 +241,7 @@ class _ListViewPageState extends State<ListViewPage> {
title: Row(
children: [
Text(
'好春光,不如夢一場!',
'${_list[index]["restaurantName"]}',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 14.0,
......@@ -185,7 +255,7 @@ class _ListViewPageState extends State<ListViewPage> {
),
// 副標題
subtitle: Text(
'2022-4-7 16:53:19',
'${_list[index]['createTime']}',
style: TextStyle(
fontSize: 12.0,
),
......@@ -194,17 +264,12 @@ class _ListViewPageState extends State<ListViewPage> {
),
const Divider(),
Container(
padding: EdgeInsets.fromLTRB(70.0, 0.0, 16.0, 0.0),
child: Row(
children: [
Text('14'),
Text('x1'),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
),
child: buildFood(_list[index]['foodList']),
padding: EdgeInsets.fromLTRB(70.0, 0, 16.0, 0),
),
Container(
child: Text('共1份,總金額: \$ 14.0'),
child: Text(
'共${_list[index]["foodList"].length}份,總金額: \$ ${_list[index]['payAmount']}'),
alignment: Alignment.centerRight,
padding: EdgeInsets.all(16.0),
)
......
......@@ -2,7 +2,7 @@
* @Author: lbh
* @Date: 2022-04-07 15:24:40
* @LastEditors: lbh
* @LastEditTime: 2022-04-08 20:11:46
* @LastEditTime: 2022-04-09 14:41:29
* @Description: file content
*/
import 'package:dio/dio.dart';
......@@ -31,7 +31,8 @@ class DioManager {
// 屬性要寫在這個裡面
DioManager() {
dio.options.headers = {"apptype": "7"};
dio.options.baseUrl = 'https://hktest.ricepon.com/64377';
// dio.options.baseUrl = 'https://hktest.ricepon.com:64377';
dio.options.baseUrl = 'https://m.ricepon.com';
dio.options.connectTimeout = 5000;
dio.options.receiveTimeout = 3000;
dio.interceptors
......@@ -51,8 +52,8 @@ class DioManager {
_requstHttp(url, successCallBack, "post", params, errorCallBack);
}
_requstHttp(String url, Function successCallBack, String method, params,
Function errorCallBack) async {
_requstHttp(String url, Function successCallBack,
[method, params, errorCallBack]) async {
Response? response;
try {
if (method == 'get') {
......@@ -69,6 +70,7 @@ class DioManager {
}
}
} on DioError catch (error) {
print(error);
return '';
}
......@@ -91,9 +93,9 @@ class DioManager {
'错误码:' +
dataMap['errorCode'].toString() +
',' +
response!.data.toString());
response.data.toString());
} else if (successCallBack != null) {
successCallBack(dataMap);
successCallBack(dataStr);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment