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 @@ ...@@ -2,16 +2,15 @@
* @Author: lbh * @Author: lbh
* @Date: 2022-04-07 10:07:36 * @Date: 2022-04-07 10:07:36
* @LastEditors: lbh * @LastEditors: lbh
* @LastEditTime: 2022-04-08 20:08:20 * @LastEditTime: 2022-04-13 16:28:24
* @Description: file content * @Description: file content
*/ */
import 'dart:developer'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:flutter_one/detail.dart';
import "./base/GlobalConfig.dart"; import "./base/GlobalConfig.dart";
import 'package:dio/dio.dart';
import 'util/DioManager.dart'; import 'util/DioManager.dart';
main() { main() {
...@@ -23,8 +22,12 @@ class MyApp extends StatelessWidget { ...@@ -23,8 +22,12 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const MaterialApp( return MaterialApp(
home: HomePage(), initialRoute: "/",
routes: {
orderDetail.routeName: (context) => orderDetail(),
HomePage.routeName: (context) => HomePage(), //注册首页路由
},
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
); );
} }
...@@ -32,7 +35,7 @@ class MyApp extends StatelessWidget { ...@@ -32,7 +35,7 @@ class MyApp extends StatelessWidget {
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key); const HomePage({Key? key}) : super(key: key);
static const String routeName = "/";
@override @override
State<HomePage> createState() => _HomePageState(); State<HomePage> createState() => _HomePageState();
} }
...@@ -102,15 +105,48 @@ class _ListViewPageState extends State<ListViewPage> { ...@@ -102,15 +105,48 @@ class _ListViewPageState extends State<ListViewPage> {
// 是否还有 // 是否还有
bool _hasMore = true; 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 { 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( DioManager.getInstance().get(
'/calendar/otherFunction/getOnlineSpecialGoods', {}, '/ricepon-order/api/orderInfo/getMemberOrderList',
map,
//正常回调 //正常回调
(data) { (data) {
setState(() { setState(() {
//更新UI等 print('打印數據');
print(data); print(data);
print('第二條');
print(json.decode(data));
//更新UI等
_list.addAll(json.decode(data)['data']);
}); });
}, },
//错误回调 //错误回调
...@@ -130,39 +166,73 @@ class _ListViewPageState extends State<ListViewPage> { ...@@ -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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RefreshIndicator( return RefreshIndicator(
child: ListView.builder( child: ListView.builder(
itemCount: 10, itemCount: _list.length,
controller: _scrollController,
// 上拉加载控制器 // 上拉加载控制器
itemBuilder: (context, index) { itemBuilder: (context, index) {
return InkWell( return InkWell(
onTap: () { onTap: () {
log("$index"); print("${_list[index]}");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => orderDetail(),
settings: RouteSettings(
name: "orderDetail",
),
),
);
// Navigator.of(context).pushNamed("orderDetail");
}, },
child: Container( child: Container(
margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0), margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0),
// color: Colors.white, // color: Colors.white,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.all( borderRadius: BorderRadius.all(
Radius.circular(8.0), 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( child: Column(
children: [ children: [
ListTile( ListTile(
// 左邊 // 左邊
leading: Image.network( leading: Image.network(
'https://hk-ricepon.oss-cn-hongkong.aliyuncs.com/images/member//authority/202204/1648798010297.jpeg', "${_list[index]['restaurantImg']}",
width: 40.0, width: 40.0,
height: 40.0, height: 40.0,
fit: BoxFit.cover, fit: BoxFit.cover,
...@@ -171,7 +241,7 @@ class _ListViewPageState extends State<ListViewPage> { ...@@ -171,7 +241,7 @@ class _ListViewPageState extends State<ListViewPage> {
title: Row( title: Row(
children: [ children: [
Text( Text(
'好春光,不如夢一場!', '${_list[index]["restaurantName"]}',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontSize: 14.0, fontSize: 14.0,
...@@ -185,7 +255,7 @@ class _ListViewPageState extends State<ListViewPage> { ...@@ -185,7 +255,7 @@ class _ListViewPageState extends State<ListViewPage> {
), ),
// 副標題 // 副標題
subtitle: Text( subtitle: Text(
'2022-4-7 16:53:19', '${_list[index]['createTime']}',
style: TextStyle( style: TextStyle(
fontSize: 12.0, fontSize: 12.0,
), ),
...@@ -194,17 +264,12 @@ class _ListViewPageState extends State<ListViewPage> { ...@@ -194,17 +264,12 @@ class _ListViewPageState extends State<ListViewPage> {
), ),
const Divider(), const Divider(),
Container( Container(
padding: EdgeInsets.fromLTRB(70.0, 0.0, 16.0, 0.0), child: buildFood(_list[index]['foodList']),
child: Row( padding: EdgeInsets.fromLTRB(70.0, 0, 16.0, 0),
children: [
Text('14'),
Text('x1'),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
),
), ),
Container( Container(
child: Text('共1份,總金額: \$ 14.0'), child: Text(
'共${_list[index]["foodList"].length}份,總金額: \$ ${_list[index]['payAmount']}'),
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
padding: EdgeInsets.all(16.0), padding: EdgeInsets.all(16.0),
) )
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: lbh * @Author: lbh
* @Date: 2022-04-07 15:24:40 * @Date: 2022-04-07 15:24:40
* @LastEditors: lbh * @LastEditors: lbh
* @LastEditTime: 2022-04-08 20:11:46 * @LastEditTime: 2022-04-09 14:41:29
* @Description: file content * @Description: file content
*/ */
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
...@@ -31,7 +31,8 @@ class DioManager { ...@@ -31,7 +31,8 @@ class DioManager {
// 屬性要寫在這個裡面 // 屬性要寫在這個裡面
DioManager() { DioManager() {
dio.options.headers = {"apptype": "7"}; 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.connectTimeout = 5000;
dio.options.receiveTimeout = 3000; dio.options.receiveTimeout = 3000;
dio.interceptors dio.interceptors
...@@ -51,8 +52,8 @@ class DioManager { ...@@ -51,8 +52,8 @@ class DioManager {
_requstHttp(url, successCallBack, "post", params, errorCallBack); _requstHttp(url, successCallBack, "post", params, errorCallBack);
} }
_requstHttp(String url, Function successCallBack, String method, params, _requstHttp(String url, Function successCallBack,
Function errorCallBack) async { [method, params, errorCallBack]) async {
Response? response; Response? response;
try { try {
if (method == 'get') { if (method == 'get') {
...@@ -69,6 +70,7 @@ class DioManager { ...@@ -69,6 +70,7 @@ class DioManager {
} }
} }
} on DioError catch (error) { } on DioError catch (error) {
print(error);
return ''; return '';
} }
...@@ -91,9 +93,9 @@ class DioManager { ...@@ -91,9 +93,9 @@ class DioManager {
'错误码:' + '错误码:' +
dataMap['errorCode'].toString() + dataMap['errorCode'].toString() +
',' + ',' +
response!.data.toString()); response.data.toString());
} else if (successCallBack != null) { } 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