Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
F
flutter_demo
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
徐群-ios
flutter_demo
提交
c0e5879b
提交
c0e5879b
编写于
2月 23, 2023
作者:
ramon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: 完成定制产品产品列表页功能;
上级
9438de01
变更
6
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
99 行增加
和
13 行删除
+99
-13
launch.json
.vscode/launch.json
+6
-0
Customization.dart
lib/Customization/Customization.dart
+55
-7
ProductListViewModel.dart
lib/Customization/ViewModel/ProductListViewModel.dart
+25
-6
main.dart
lib/main.dart
+4
-0
pubspec.lock
pubspec.lock
+8
-0
pubspec.yaml
pubspec.yaml
+1
-0
未找到文件。
.vscode/launch.json
浏览文件 @
c0e5879b
...
...
@@ -16,6 +16,12 @@
"type"
:
"dart"
,
"deviceId"
:
"1DA4CCCC-D0B8-47DF-B671-FAC9B80F7030"
},
{
"name"
:
"Ramon Mac(iOS模拟器)"
,
"request"
:
"launch"
,
"type"
:
"dart"
,
"deviceId"
:
"B7195A0C-A207-403A-AEF5-ACD3D72C22B6"
},
{
"name"
:
"my_app2 (profile mode)"
,
"request"
:
"launch"
,
...
...
lib/Customization/Customization.dart
浏览文件 @
c0e5879b
import
'dart:math'
as
math
;
import
'package:easy_refresh/easy_refresh.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_spinkit/flutter_spinkit.dart'
;
import
'package:my_app2/Assets/AssetImages.dart'
;
import
'package:my_app2/Customization/ViewModel/ProductListViewModel.dart'
;
import
'package:my_app2/Models/ProductModel.dart'
;
...
...
@@ -37,21 +39,37 @@ class _CustomizationListImg extends StatefulWidget {
}
class
_CustomizationListImgState
extends
State
<
_CustomizationListImg
>
{
late
EasyRefreshController
_refreshController
;
@override
void
initState
()
{
super
.
initState
();
widget
.
viewModel
.
pullUp
();
_refreshController
=
widget
.
viewModel
.
refreshController
;
// widget.viewModel.pullUp();
}
@override
void
dispose
()
{
_refreshController
.
dispose
();
super
.
dispose
();
}
void
_onRefresh
()
{
widget
.
viewModel
.
refresh
();
}
void
_onLoad
()
{
widget
.
viewModel
.
loadMore
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
Consumer
<
ProductListViewModel
>(
builder:
(
context
,
viewModel
,
child
)
{
if
(
viewModel
.
isLoading
)
{
return
const
Center
(
child:
CircularProgressIndicator
(),
);
}
//
if (viewModel.isLoading) {
//
return const Center(
//
child: CircularProgressIndicator(),
//
);
//
}
List
<
Widget
>
slivers
=
[];
if
(
viewModel
.
photoProductList
.
isNotEmpty
&&
...
...
@@ -105,7 +123,37 @@ class _CustomizationListImgState extends State<_CustomizationListImg> {
),
];
}
return
CustomScrollView
(
slivers:
slivers
);
// return CustomScrollView(slivers: slivers);
final
themeData
=
Theme
.
of
(
context
);
return
EasyRefresh
(
controller:
_refreshController
,
refreshOnStart:
true
,
refreshOnStartHeader:
BuilderHeader
(
triggerOffset:
70
,
clamping:
true
,
position:
IndicatorPosition
.
above
,
processedDuration:
Duration
.
zero
,
builder:
(
context
,
state
)
{
if
(
state
.
mode
==
IndicatorMode
.
inactive
||
state
.
mode
==
IndicatorMode
.
done
)
{
return
const
SizedBox
();
}
return
Container
(
padding:
const
EdgeInsets
.
only
(
bottom:
100
),
width:
double
.
infinity
,
height:
state
.
viewportDimension
,
alignment:
Alignment
.
center
,
child:
SpinKitDoubleBounce
(
size:
32
,
color:
themeData
.
colorScheme
.
primary
,
),
);
},
),
onRefresh:
_onRefresh
,
onLoad:
_onLoad
,
child:
CustomScrollView
(
slivers:
slivers
),
);
},
);
}
...
...
lib/Customization/ViewModel/ProductListViewModel.dart
浏览文件 @
c0e5879b
import
'package:easy_refresh/easy_refresh.dart'
;
import
'package:flutter/material.dart'
;
import
'package:my_app2/Models/ProductModel.dart'
;
import
'package:my_app2/Network/api/product_api.dart'
;
import
'package:my_app2/Network/http/BaseApi.dart'
;
class
ProductListViewModel
extends
ChangeNotifier
{
final
EasyRefreshController
refreshController
=
EasyRefreshController
(
controlFinishRefresh:
true
,
controlFinishLoad:
true
);
final
List
<
ProductModel
>
_productList
=
[];
int
_page
=
1
;
...
...
@@ -48,18 +52,33 @@ class ProductListViewModel extends ChangeNotifier {
return
_productList
.
sublist
(
index
);
}
void
pullUp
()
{
void
refresh
()
{
var
api
=
ProductListApi
(
page:
1
,
pageSize:
_pageSize
);
api
.
request
(
onSuccessed:
(
value
)
{
if
(
value
==
null
)
{
return
;
}
_updateProductList
(
value
,
true
);
var
list
=
value
??
[];
_page
=
1
;
refreshController
.
finishRefresh
();
refreshController
.
resetFooter
;
_updateProductList
(
list
,
true
);
},
onFailed:
(
p0
)
{},
);
}
void
loadMore
()
{}
void
loadMore
()
{
var
api
=
ProductListApi
(
page:
_page
+
1
,
pageSize:
_pageSize
);
api
.
request
(
onSuccessed:
(
value
)
{
var
list
=
value
??
[];
_page
+=
1
;
refreshController
.
finishLoad
(
list
.
length
>=
_pageSize
?
IndicatorResult
.
success
:
IndicatorResult
.
noMore
);
_updateProductList
(
list
,
false
);
},
onFailed:
(
p0
)
{},
);
}
}
lib/main.dart
浏览文件 @
c0e5879b
...
...
@@ -40,6 +40,10 @@ class MyApp extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
.
router
(
theme:
ThemeData
(
brightness:
Brightness
.
light
,
colorSchemeSeed:
const
Color
(
0xFFFFAA22
),
useMaterial3:
true
),
routerConfig:
_router
,
);
}
...
...
pubspec.lock
浏览文件 @
c0e5879b
...
...
@@ -238,6 +238,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
flutter_spinkit:
dependency: "direct main"
description:
name: flutter_spinkit
sha256: "77a2117c0517ff909221f3160b8eb20052ab5216107581168af574ac1f05dff8"
url: "https://pub.dev"
source: hosted
version: "5.1.0"
flutter_swiper_view:
dependency: "direct main"
description:
...
...
pubspec.yaml
浏览文件 @
c0e5879b
...
...
@@ -42,6 +42,7 @@ dependencies:
dio
:
^5.0.0
provider
:
^6.0.5
easy_refresh
:
^3.3.1
flutter_spinkit
:
^5.1.0
dev_dependencies
:
flutter_test
:
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录