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
523509f1
Commit
523509f1
authored
Apr 08, 2022
by
liubohua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
9c46f08c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
15 deletions
+56
-15
lib/main.dart
+43
-14
lib/util/DioManager.dart
+13
-1
No files found.
lib/main.dart
View file @
523509f1
...
...
@@ -2,14 +2,17 @@
* @Author: lbh
* @Date: 2022-04-07 10:07:36
* @LastEditors: lbh
* @LastEditTime: 2022-04-08
12:05:0
0
* @LastEditTime: 2022-04-08
20:08:2
0
* @Description: file content
*/
import
'dart:
html
'
;
import
'dart:
developer
'
;
import
'package:flutter/material.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
"./base/GlobalConfig.dart"
;
import
'package:dio/dio.dart'
;
import
'util/DioManager.dart'
;
main
()
{
runApp
(
const
MyApp
());
...
...
@@ -56,8 +59,8 @@ class _HomePageState extends State<HomePage> {
backgroundColor:
Colors
.
white
,
bottom:
TabBar
(
labelColor:
GlobalConfig
.
themeColor
,
indicatorColor:
GlobalConfig
.
themeColor
,
unselectedLabelColor:
GlobalConfig
.
fontColor
,
indicatorColor:
GlobalConfig
.
themeColor
,
//選中顏色
unselectedLabelColor:
GlobalConfig
.
fontColor
,
// 未選中顏色
tabs:
[
Tab
(
text:
'全部'
,
...
...
@@ -92,24 +95,53 @@ class ListViewPage extends StatefulWidget {
}
class
_ListViewPageState
extends
State
<
ListViewPage
>
{
// 当前页数
int
_page
=
1
;
// 页面数据
List
_list
=
[];
// 是否还有
bool
_hasMore
=
true
;
void
_getData
()
async
{
if
(
this
.
_hasMore
)
{
DioManager
.
getInstance
().
get
(
'/calendar/otherFunction/getOnlineSpecialGoods'
,
{},
//正常回调
(
data
)
{
setState
(()
{
//更新UI等
print
(
data
);
});
},
//错误回调
(
error
)
{
print
(
"网络异常,请稍后重试"
);
},
);
}
}
// 下拉刷新
Future
<
void
>
_onRefresh
()
async
{
print
(
"下拉刷新"
);
// 持续两秒
await
Future
.
delayed
(
Duration
(
milliseconds:
2000
),
()
{});
await
Future
.
delayed
(
Duration
(
milliseconds:
2000
),
()
{
_getData
();
});
}
@override
Widget
build
(
BuildContext
context
)
{
return
RefreshIndicator
(
child:
ListView
.
builder
(
itemCount:
10
,
// 上拉加载控制器
itemBuilder:
(
context
,
index
)
{
Widget
tip
=
const
Text
(
""
);
return
Column
(
children:
[
Container
(
return
InkWell
(
onTap:
()
{
log
(
"
$index
"
);
},
child:
Container
(
margin:
EdgeInsets
.
fromLTRB
(
10.0
,
10.0
,
10.0
,
0.0
),
// color: Colors.white,
decoration:
BoxDecoration
(
...
...
@@ -122,7 +154,7 @@ class _ListViewPageState extends State<ListViewPage> {
color:
Colors
.
grey
,
offset:
Offset
(
0.0
,
1.0
),
//阴影y轴偏移量
blurRadius:
2.0
,
//阴影模糊程度
spreadRadius:
0
//阴影扩散程度
spreadRadius:
0
,
//阴影扩散程度
)
]),
child:
Column
(
...
...
@@ -179,9 +211,6 @@ class _ListViewPageState extends State<ListViewPage> {
],
),
),
// 加载提示
tip
],
);
},
),
...
...
lib/util/
dio
.dart
→
lib/util/
DioManager
.dart
View file @
523509f1
...
...
@@ -2,7 +2,7 @@
* @Author: lbh
* @Date: 2022-04-07 15:24:40
* @LastEditors: lbh
* @LastEditTime: 2022-04-0
7 16:05:11
* @LastEditTime: 2022-04-0
8 20:11:46
* @Description: file content
*/
import
'package:dio/dio.dart'
;
...
...
@@ -15,7 +15,19 @@ import '../base/GlobalConfig.dart';
* 网络请求管理类
*/
class
DioManager
{
//写一个单例
//在 Dart 里,带下划线开头的变量是私有变量
static
DioManager
_instance
=
DioManager
();
static
DioManager
getInstance
()
{
if
(
_instance
==
null
)
{
_instance
=
DioManager
();
}
return
_instance
;
}
Dio
dio
=
Dio
();
// 屬性要寫在這個裡面
DioManager
()
{
dio
.
options
.
headers
=
{
"apptype"
:
"7"
};
...
...
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