Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
flutter-demo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘博华
flutter-demo
Commits
af91fec7
Commit
af91fec7
authored
Apr 07, 2022
by
liubohua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
4db1ce97
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
299 additions
and
89 deletions
+299
-89
lib/base/GlobalConfig.dart
+18
-0
lib/main.dart
+94
-85
lib/util/ResultCode.dart
+32
-0
lib/util/dio.dart
+93
-0
pubspec.lock
+48
-0
pubspec.yaml
+14
-4
No files found.
lib/base/GlobalConfig.dart
0 → 100644
View file @
af91fec7
/*
* @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
);
}
lib/main.dart
View file @
af91fec7
/*
* @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
My
HomePage
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
@override
// that it has a State object (defined below) that contains fields that affect
State
<
HomePage
>
createState
()
=>
_HomePageState
();
// how it looks.
}
// This class is the configuration for the state. It holds the values (in this
class
_HomePageState
extends
State
<
HomePage
>
{
// case the title) provided by the parent (in this case the App widget) and
@override
// used by the build method of the State. Fields in a Widget subclass are
Widget
build
(
BuildContext
context
)
{
// always marked "final".
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'我的訂單'
),
titleTextStyle:
const
TextStyle
(
fontSize:
16.0
,
color:
Colors
.
white
,
),
centerTitle:
true
,
backgroundColor:
GlobalConfig
.
themeColor
,
toolbarHeight:
46.0
,
),
body:
DefaultTabController
(
length:
3
,
child:
Scaffold
(
appBar:
AppBar
(
toolbarHeight:
0.0
,
backgroundColor:
Colors
.
white
,
bottom:
TabBar
(
labelColor:
GlobalConfig
.
themeColor
,
indicatorColor:
GlobalConfig
.
themeColor
,
unselectedLabelColor:
GlobalConfig
.
fontColor
,
tabs:
[
Tab
(
text:
'全部'
,
),
Tab
(
text:
'待付款'
,
),
Tab
(
text:
'點評/投票'
,
),
],
),
),
body:
const
TabBarView
(
children:
[
ListViewPage
(),
ListViewPage
(),
ListViewPage
(),
],
),
),
),
);
}
}
final
String
title
;
class
ListViewPage
extends
StatefulWidget
{
const
ListViewPage
({
Key
?
key
})
:
super
(
key:
key
);
@override
@override
State
<
MyHomePage
>
createState
()
=>
_MyHome
PageState
();
State
<
ListViewPage
>
createState
()
=>
_ListView
PageState
();
}
}
class
_MyHomePageState
extends
State
<
MyHomePage
>
{
class
_ListViewPageState
extends
State
<
ListViewPage
>
{
int
_counter
=
0
;
// 下拉刷新
Future
<
void
>
_onRefresh
()
async
{
void
_incrementCounter
()
{
print
(
"下拉刷新"
);
setState
(()
{
// 持续两秒
// This call to setState tells the Flutter framework that something has
await
Future
.
delayed
(
Duration
(
milliseconds:
2000
),
()
{});
// 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
return
RefreshIndicator
(
// by the _incrementCounter method above.
child:
ListView
.
builder
(
//
// 上拉加载控制器
// The Flutter framework has been optimized to make rerunning build methods
itemBuilder:
(
context
,
index
)
{
// fast, so that you can just rebuild anything that needs updating rather
Widget
tip
=
const
Text
(
""
);
// than having to individually change instances of widgets.
return
Scaffold
(
return
Column
(
appBar:
AppBar
(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title:
Text
(
widget
.
title
),
),
body:
Center
(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child:
Column
(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
children:
<
Widget
>[
const
Text
(
ListTile
(
'You have pushed the button this many times:'
,
title:
Text
(
),
"10"
,
Text
(
maxLines:
1
,
'
$_counter
'
,
)),
style:
Theme
.
of
(
context
).
textTheme
.
headline4
,
const
Divider
(),
),
// 加载提示
tip
],
],
),
);
),
}),
floatingActionButton:
FloatingActionButton
(
onRefresh:
_onRefresh
,
onPressed:
_incrementCounter
,
tooltip:
'Increment'
,
child:
const
Icon
(
Icons
.
add
),
),
// This trailing comma makes auto-formatting nicer for build methods.
);
);
}
}
}
}
lib/util/ResultCode.dart
0 → 100644
View file @
af91fec7
/*
* @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
;
}
lib/util/dio.dart
0 → 100644
View file @
af91fec7
/*
* @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
);
}
}
}
pubspec.lock
View file @
af91fec7
...
@@ -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"
pubspec.yaml
View file @
af91fec7
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment