Commit af91fec7 by liubohua

1

parent 4db1ce97
/*
* @Author: lbh
* @Date: 2022-04-07 15:31:49
* @LastEditors: lbh
* @LastEditTime: 2022-04-07 15:55:58
* @Description: file content
*/
import 'package:flutter/material.dart';
/*
*系统主题设置,包括系统默认字体 背景色等
*/
class GlobalConfig {
static bool isDebug = true; //是否是调试模式
static bool dark = false;
static Color fontColor = Colors.black54;
static Color themeColor = const Color.fromARGB(255, 190, 28, 66);
}
/*
* @Author: lbh
* @Date: 2022-04-07 10:07:36
* @LastEditors: lbh
* @LastEditTime: 2022-04-07 16:02:35
* @Description: file content
*/
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import "./base/GlobalConfig.dart";
void main() { main() {
runApp(const MyApp()); runApp(const MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return const MaterialApp(
title: 'Flutter Demo', home: HomePage(),
theme: ThemeData( debugShowCheckedModeBanner: false,
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
); );
} }
} }
class MyHomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key); const HomePage({Key? key}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override @override
State<MyHomePage> createState() => _MyHomePageState(); State<HomePage> createState() => _HomePageState();
} }
class _MyHomePageState extends State<MyHomePage> { class _HomePageState extends State<HomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by title: const Text('我的訂單'),
// the App.build method, and use it to set our appbar title. titleTextStyle: const TextStyle(
title: Text(widget.title), fontSize: 16.0,
color: Colors.white,
), ),
body: Center( centerTitle: true,
// Center is a layout widget. It takes a single child and positions it backgroundColor: GlobalConfig.themeColor,
// in the middle of the parent. toolbarHeight: 46.0,
child: Column( ),
// Column is also a layout widget. It takes a list of children and body: DefaultTabController(
// arranges them vertically. By default, it sizes itself to fit its length: 3,
// children horizontally, and tries to be as tall as its parent. child: Scaffold(
// appBar: AppBar(
// Invoke "debug painting" (press "p" in the console, choose the toolbarHeight: 0.0,
// "Toggle Debug Paint" action from the Flutter Inspector in Android backgroundColor: Colors.white,
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code) bottom: TabBar(
// to see the wireframe for each widget. labelColor: GlobalConfig.themeColor,
// indicatorColor: GlobalConfig.themeColor,
// Column has various properties to control how it sizes itself and unselectedLabelColor: GlobalConfig.fontColor,
// how it positions its children. Here we use mainAxisAlignment to tabs: [
// center the children vertically; the main axis here is the vertical Tab(
// axis because Columns are vertical (the cross axis would be text: '全部',
// horizontal). ),
mainAxisAlignment: MainAxisAlignment.center, Tab(
children: <Widget>[ text: '待付款',
const Text(
'You have pushed the button this many times:',
), ),
Text( Tab(
'$_counter', text: '點評/投票',
style: Theme.of(context).textTheme.headline4,
), ),
], ],
), ),
), ),
floatingActionButton: FloatingActionButton( body: const TabBarView(
onPressed: _incrementCounter, children: [
tooltip: 'Increment', ListViewPage(),
child: const Icon(Icons.add), ListViewPage(),
), // This trailing comma makes auto-formatting nicer for build methods. ListViewPage(),
],
),
),
),
);
}
}
class ListViewPage extends StatefulWidget {
const ListViewPage({Key? key}) : super(key: key);
@override
State<ListViewPage> createState() => _ListViewPageState();
}
class _ListViewPageState extends State<ListViewPage> {
// 下拉刷新
Future<void> _onRefresh() async {
print("下拉刷新");
// 持续两秒
await Future.delayed(Duration(milliseconds: 2000), () {});
}
@override
Widget build(BuildContext context) {
return RefreshIndicator(
child: ListView.builder(
// 上拉加载控制器
itemBuilder: (context, index) {
Widget tip = const Text("");
return Column(
children: <Widget>[
ListTile(
title: Text(
"10",
maxLines: 1,
)),
const Divider(),
// 加载提示
tip
],
);
}),
onRefresh: _onRefresh,
); );
} }
} }
/*
* @Author: lbh
* @Date: 2022-04-07 15:26:38
* @LastEditors: lbh
* @LastEditTime: 2022-04-07 15:26:38
* @Description: file content
*/
/*
* dio网络请求失败的回调错误码
*/
class ResultCode {
//正常返回是1
static const SUCCESS = 1;
//异常返回是0
static const ERROR = 0;
/// When opening url timeout, it occurs.
static const CONNECT_TIMEOUT = -1;
///It occurs when receiving timeout.
static const RECEIVE_TIMEOUT = -2;
/// When the server response, but with a incorrect status, such as 404, 503...
static const RESPONSE = -3;
/// When the request is cancelled, dio will throw a error with this type.
static const CANCEL = -4;
/// read the DioError.error if it is not null.
static const DEFAULT = -5;
}
/*
* @Author: lbh
* @Date: 2022-04-07 15:24:40
* @LastEditors: lbh
* @LastEditTime: 2022-04-07 16:05:11
* @Description: file content
*/
import 'package:dio/dio.dart';
import 'dart:convert';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import '../base/GlobalConfig.dart';
/*
* 网络请求管理类
*/
class DioManager {
Dio dio = Dio();
// 屬性要寫在這個裡面
DioManager() {
dio.options.headers = {"apptype": "7"};
dio.options.baseUrl = 'https://hktest.ricepon.com/64377';
dio.options.connectTimeout = 5000;
dio.options.receiveTimeout = 3000;
dio.interceptors
.add(LogInterceptor(responseBody: GlobalConfig.isDebug)); //是否开启请求日志
dio.interceptors.add(CookieManager(CookieJar())); //缓存相关类
}
//get请求
get(String url, Map params, Function successCallBack,
Function errorCallBack) async {
_requstHttp(url, successCallBack, 'get', params, errorCallBack);
}
//post请求
post(String url, params, Function successCallBack,
Function errorCallBack) async {
_requstHttp(url, successCallBack, "post", params, errorCallBack);
}
_requstHttp(String url, Function successCallBack, String method, params,
Function errorCallBack) async {
Response? response;
try {
if (method == 'get') {
if (params != null && params.length > 0) {
response = await dio.get(url, queryParameters: params);
} else {
response = await dio.get(url);
}
} else if (method == 'post') {
if (params != null && params.length > 0) {
response = await dio.post(url, data: params);
} else {
response = await dio.post(url);
}
}
} on DioError catch (error) {
return '';
}
// debug模式打印相关数据
if (GlobalConfig.isDebug) {
print('请求url: ' + url);
print('请求头: ' + dio.options.headers.toString());
if (params != null) {
print('请求参数: ' + params.toString());
}
if (response != null) {
print('返回参数: ' + response.toString());
}
}
String dataStr = json.encode(response!.data);
Map<String, dynamic> dataMap = json.decode(dataStr);
if (dataMap == null || dataMap['state'] == 0) {
_error(
errorCallBack,
'错误码:' +
dataMap['errorCode'].toString() +
',' +
response!.data.toString());
} else if (successCallBack != null) {
successCallBack(dataMap);
}
}
_error(Function errorCallBack, String error) {
if (errorCallBack != null) {
errorCallBack(error);
}
}
}
...@@ -43,6 +43,13 @@ packages: ...@@ -43,6 +43,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.15.0" version: "1.15.0"
cookie_jar:
dependency: "direct main"
description:
name: cookie_jar
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
...@@ -50,6 +57,20 @@ packages: ...@@ -50,6 +57,20 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
dio:
dependency: "direct main"
description:
name: dio
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.6"
dio_cookie_manager:
dependency: "direct main"
description:
name: dio_cookie_manager
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
...@@ -74,6 +95,32 @@ packages: ...@@ -74,6 +95,32 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
fluttertoast:
dependency: "direct main"
description:
name: fluttertoast
url: "https://pub.flutter-io.cn"
source: hosted
version: "7.1.8"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.3"
lints: lints:
dependency: transitive dependency: transitive
description: description:
...@@ -172,3 +219,4 @@ packages: ...@@ -172,3 +219,4 @@ packages:
version: "2.1.1" version: "2.1.1"
sdks: sdks:
dart: ">=2.16.1 <3.0.0" dart: ">=2.16.1 <3.0.0"
flutter: ">=1.10.0"
...@@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev ...@@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.16.1 <3.0.0" sdk: '>=2.16.1 <3.0.0'
# Dependencies specify other packages that your package needs in order to work. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions
...@@ -30,10 +30,21 @@ dependencies: ...@@ -30,10 +30,21 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2 cupertino_icons:
^1.0.2
#网络库-dio
dio:
^4.0.6
#网络库-cookie
cookie_jar:
^3.0.1
#网络库-cookieManager
dio_cookie_manager:
^2.0.0
#flutter中的提示
fluttertoast: ^7.1.5
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
...@@ -51,7 +62,6 @@ dev_dependencies: ...@@ -51,7 +62,6 @@ dev_dependencies:
# The following section is specific to Flutter. # The following section is specific to Flutter.
flutter: flutter:
# The following line ensures that the Material Icons font is # The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in # included with your application, so that you can use the icons in
# the material Icons class. # the material Icons class.
......
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