Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
F
flutter_demo
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
徐群-ios
flutter_demo
提交
9438de01
提交
9438de01
编写于
2月 23, 2023
作者:
徐群-ios
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: 集成列表功能开发
上级
edf184fe
变更
11
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
322 行增加
和
65 行删除
+322
-65
right_arrow.png
assets/multiImgs/2.0x/right_arrow.png
+0
-0
right_arrow.png
assets/multiImgs/3.0x/right_arrow.png
+0
-0
right_arrow.png
assets/multiImgs/right_arrow.png
+0
-0
AssetImages.dart
lib/Assets/AssetImages.dart
+5
-0
Customization.dart
lib/Customization/Customization.dart
+151
-45
ProductListViewModel.dart
lib/Customization/ViewModel/ProductListViewModel.dart
+65
-0
BaseApi.dart
lib/Network/http/BaseApi.dart
+0
-16
TabPageContainer.dart
lib/TabPageContainer.dart
+55
-0
main.dart
lib/main.dart
+4
-4
pubspec.lock
pubspec.lock
+40
-0
pubspec.yaml
pubspec.yaml
+2
-0
未找到文件。
assets/multiImgs/2.0x/right_arrow.png
0 → 100644
浏览文件 @
9438de01
320 字节
assets/multiImgs/3.0x/right_arrow.png
0 → 100644
浏览文件 @
9438de01
615 字节
assets/multiImgs/right_arrow.png
0 → 100644
浏览文件 @
9438de01
223 字节
lib/Assets/AssetImages.dart
0 → 100644
浏览文件 @
9438de01
// ignore_for_file: constant_identifier_names
class
AssetImages
{
static
const
String
right_arrow
=
'assets/multiImgs/right_arrow.png'
;
}
lib/Customization/Customization.dart
浏览文件 @
9438de01
import
'dart:math'
as
math
;
import
'dart:math'
as
math
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:my_app2/Network/api/product_api.dart'
;
import
'package:my_app2/Assets/AssetImages.dart'
;
import
'package:my_app2/Network/http/BaseApi.dart'
;
import
'package:my_app2/Customization/ViewModel/ProductListViewModel.dart'
;
import
'package:my_app2/Models/ProductModel.dart'
;
import
'package:provider/provider.dart'
;
class
Customization
extends
State
ful
Widget
{
class
Customization
extends
State
less
Widget
{
const
Customization
({
super
.
key
});
const
Customization
({
super
.
key
});
State
<
Customization
>
createState
()
=>
_CustomizationState
();
@override
Widget
build
(
BuildContext
context
)
{
return
ChangeNotifierProvider
(
create:
(
context
)
=>
ProductListViewModel
(),
child:
_CustomizationList
(),
);
}
}
class
_CustomizationList
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
var
viewModel
=
Provider
.
of
<
ProductListViewModel
>(
context
);
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'热门产品'
)),
body:
_CustomizationListImg
(
viewModel
),
);
}
}
}
class
_CustomizationState
extends
State
<
Customization
>
{
class
_CustomizationListImg
extends
StatefulWidget
{
const
_CustomizationListImg
(
this
.
viewModel
);
final
ProductListViewModel
viewModel
;
@override
State
<
_CustomizationListImg
>
createState
()
=>
_CustomizationListImgState
();
}
class
_CustomizationListImgState
extends
State
<
_CustomizationListImg
>
{
@override
@override
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
ProductListApi
request
=
ProductListApi
(
page:
1
,
pageSize:
10
);
widget
.
viewModel
.
pullUp
();
request
.
request
(
onSuccessed:
(
value
)
{
print
(
value
);
},
onFailed:
(
error
)
{
print
(
error
.
toString
());
});
}
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
List
<
String
>
dataSource
=
[
return
Consumer
<
ProductListViewModel
>(
"https://static.preclight.com/uploads/2023-02-08/63e36bec6e8f4.png"
,
builder:
(
context
,
viewModel
,
child
)
{
"https://static.preclight.com/uploads/2023-02-20/63f2e9568b736.jpg"
,
if
(
viewModel
.
isLoading
)
{
"https://static.preclight.com/uploads/2023-02-07/63e219498801e.jpg"
,
return
const
Center
(
"https://static.preclight.com/uploads/2023-02-07/63e2123ea9287.jpg"
,
child:
CircularProgressIndicator
(),
"https://static.preclight.com/uploads/2023-02-07/63e21685eb2b4.png"
,
);
"https://static.preclight.com/uploads/2023-01-31/63d8f975dc915.jpg"
,
}
"https://static.preclight.com/uploads/2023-01-31/63d8f4cde0315.jpg"
,
"https://static.preclight.com/uploads/2023-02-22/63f59104a7fe7.png"
,
List
<
Widget
>
slivers
=
[];
"https://static.preclight.com/uploads/2023-01-19/63c8e4eb35d16.png"
,
if
(
viewModel
.
photoProductList
.
isNotEmpty
&&
"https://static.preclight.com/uploads/2022-11-30/6387278fd8022.jpg"
viewModel
.
handmadeProductList
.
isNotEmpty
)
{
];
slivers
=
[
return
Scaffold
(
SliverPadding
(
appBar:
AppBar
(
title:
const
Text
(
'热门产品'
)),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
body:
CustomScrollView
(
slivers:
[
sliver:
_ListHeader
(
'3D照片'
),
SliverPadding
(
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
SliverPadding
(
sliver:
SliverList
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
delegate:
ProductSliverBuilderDelegate
(
dataSource
,
10
)),
sliver:
SliverList
(
),
delegate:
_ProductSliverBuilderDelegate
(
SliverList
(
viewModel
.
photoProductList
,
10
)),
delegate:
),
SliverChildBuilderDelegate
((
BuildContext
context
,
int
index
)
{
SliverPadding
(
return
const
SizedBox
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
height:
40
,
sliver:
_ListHeader
(
'3D定制手办'
),
child:
Text
(
"hello world"
),
),
);
SliverPadding
(
},
childCount:
2
))
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
]));
sliver:
SliverList
(
delegate:
_ProductSliverBuilderDelegate
(
viewModel
.
handmadeProductList
,
10
)),
),
];
}
else
if
(
viewModel
.
photoProductList
.
isNotEmpty
)
{
slivers
=
[
SliverPadding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
sliver:
_ListHeader
(
'3D照片'
),
),
SliverPadding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
sliver:
SliverList
(
delegate:
_ProductSliverBuilderDelegate
(
viewModel
.
photoProductList
,
10
)),
),
];
}
else
if
(
viewModel
.
handmadeProductList
.
isNotEmpty
)
{
slivers
=
[
SliverPadding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
sliver:
_ListHeader
(
'3D定制手办'
),
),
SliverPadding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
12
),
sliver:
SliverList
(
delegate:
_ProductSliverBuilderDelegate
(
viewModel
.
handmadeProductList
,
10
)),
),
];
}
return
CustomScrollView
(
slivers:
slivers
);
},
);
}
}
}
}
class
ProductSliverBuilderDelegate
extends
SliverChildBuilderDelegate
{
class
_ListHeader
extends
SliverToBoxAdapter
{
_ListHeader
(
String
title
,
{
double
height
=
50.0
})
:
assert
(
height
>
0
),
super
(
child:
SizedBox
(
height:
height
,
child:
Row
(
children:
[
Container
(
width:
4
,
height:
14
,
decoration:
const
BoxDecoration
(
color:
Color
(
0xFFFFAA22
),
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
))),
),
const
SizedBox
(
width:
6
,
),
Text
(
title
,
style:
const
TextStyle
(
fontSize:
16.0
,
fontWeight:
FontWeight
.
w600
),
)
]),
));
}
class
_ProductSliverBuilderDelegate
extends
SliverChildBuilderDelegate
{
static
int
_computeActualChildCount
(
int
itemCount
)
{
static
int
_computeActualChildCount
(
int
itemCount
)
{
return
math
.
max
(
0
,
itemCount
*
2
-
1
);
return
math
.
max
(
0
,
itemCount
*
2
-
1
);
}
}
final
List
<
String
>
dataSource
;
final
List
<
ProductModel
>
dataSource
;
final
double
spacing
;
final
double
spacing
;
ProductSliverBuilderDelegate
(
this
.
dataSource
,
this
.
spacing
)
_
ProductSliverBuilderDelegate
(
this
.
dataSource
,
this
.
spacing
)
:
assert
(
spacing
>
0
),
:
assert
(
spacing
>
0
),
super
((
context
,
index
)
{
super
((
context
,
index
)
{
final
int
itemIndex
=
index
~/
2
;
final
int
itemIndex
=
index
~/
2
;
final
Widget
?
widget
;
final
Widget
?
widget
;
if
(
index
.
isEven
)
{
if
(
index
.
isEven
)
{
double
height
=
MediaQuery
.
of
(
context
).
size
.
width
-
12.0
*
2
;
double
height
=
MediaQuery
.
of
(
context
).
size
.
width
-
12.0
*
2
;
String
imgUrl
=
dataSource
[
itemIndex
];
var
item
=
dataSource
[
itemIndex
];
String
imgUrl
=
item
.
cover
;
widget
=
Container
(
widget
=
Container
(
decoration:
const
BoxDecoration
(
decoration:
const
BoxDecoration
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
12.0
))),
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
12.0
))),
...
@@ -78,7 +160,31 @@ class ProductSliverBuilderDelegate extends SliverChildBuilderDelegate {
...
@@ -78,7 +160,31 @@ class ProductSliverBuilderDelegate extends SliverChildBuilderDelegate {
height:
height
,
height:
height
,
child:
Stack
(
child:
Stack
(
fit:
StackFit
.
expand
,
fit:
StackFit
.
expand
,
children:
[
Image
.
network
(
imgUrl
)],
children:
[
Image
.
network
(
imgUrl
),
Positioned
(
left:
0
,
right:
0
,
bottom:
0
,
child:
Container
(
color:
Colors
.
black
.
withOpacity
(
0.3
),
height:
50
,
child:
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
15
),
child:
Row
(
children:
[
Expanded
(
child:
Text
(
item
.
productName
,
style:
const
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
w600
),
)),
Image
.
asset
(
AssetImages
.
right_arrow
)
]),
),
),
)
],
),
),
);
);
}
else
{
}
else
{
...
...
lib/Customization/ViewModel/ProductListViewModel.dart
0 → 100644
浏览文件 @
9438de01
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
List
<
ProductModel
>
_productList
=
[];
int
_page
=
1
;
final
int
_pageSize
=
10
;
bool
_isLoading
=
true
;
bool
get
isLoading
=>
_isLoading
&&
_productList
.
isEmpty
;
bool
get
isEmpty
=>
_productList
.
isEmpty
;
void
_updateProductList
(
List
<
ProductModel
>
list
,
bool
isClear
)
{
_isLoading
=
false
;
if
(
isClear
)
{
_productList
.
clear
();
}
_productList
.
addAll
(
list
);
notifyListeners
();
}
/// 3d照片
List
<
ProductModel
>
get
photoProductList
{
var
list
=
<
ProductModel
>[];
for
(
final
item
in
_productList
)
{
if
(
item
.
productType
==
2
)
{
list
.
add
(
item
);
continue
;
}
break
;
}
return
list
;
}
/// 手办
List
<
ProductModel
>
get
handmadeProductList
{
int
index
=
0
;
for
(
index
;
index
<
_productList
.
length
;
index
++)
{
if
(
_productList
[
index
].
productType
==
1
)
{
break
;
}
}
return
_productList
.
sublist
(
index
);
}
void
pullUp
()
{
var
api
=
ProductListApi
(
page:
1
,
pageSize:
_pageSize
);
api
.
request
(
onSuccessed:
(
value
)
{
if
(
value
==
null
)
{
return
;
}
_updateProductList
(
value
,
true
);
},
onFailed:
(
p0
)
{},
);
}
void
loadMore
()
{}
}
lib/Network/http/BaseApi.dart
浏览文件 @
9438de01
...
@@ -9,22 +9,6 @@ enum RequestMethod { get, post }
...
@@ -9,22 +9,6 @@ enum RequestMethod { get, post }
typedef
HttpParams
=
Map
<
String
,
dynamic
>;
typedef
HttpParams
=
Map
<
String
,
dynamic
>;
typedef
HttpHeader
=
Map
<
String
,
dynamic
>;
typedef
HttpHeader
=
Map
<
String
,
dynamic
>;
class
Test
{
Test
(
this
.
value
);
final
int
value
;
}
class
AA
<
T
>
{
T
getResponse
(
Map
<
String
,
dynamic
>
json
)
=>
throw
Exception
(
'子类重写'
);
}
class
BB
extends
AA
<
Test
>
{
@override
Test
getResponse
(
Map
<
String
,
dynamic
>
json
)
{
return
Test
(
1
);
}
}
class
BaseApi
<
Model
>
{
class
BaseApi
<
Model
>
{
String
serviceKey
()
{
String
serviceKey
()
{
return
""
;
return
""
;
...
...
lib/TabPageContainer.dart
0 → 100644
浏览文件 @
9438de01
import
'package:flutter/material.dart'
;
/// _TabPageContainer 实现tab页面懒加载及状态保存
class
TabPageContainer
extends
StatefulWidget
{
final
List
<
Widget
>
children
;
final
int
currentIndex
;
const
TabPageContainer
(
{
Key
?
key
,
required
this
.
children
,
required
this
.
currentIndex
})
:
assert
(
currentIndex
>=
0
),
super
(
key:
key
);
@override
State
<
TabPageContainer
>
createState
()
=>
_TabPageContainerState
();
}
class
_TabPageContainerState
extends
State
<
TabPageContainer
>
{
final
initMap
=
<
int
,
bool
>{};
@override
void
initState
()
{
super
.
initState
();
initMap
[
0
]
=
true
;
}
List
<
Widget
>
createChildren
()
{
final
result
=
<
Widget
>[];
for
(
var
i
=
0
;
i
<
widget
.
children
.
length
;
++
i
)
{
final
w
=
widget
.
children
[
i
];
if
(
initMap
[
i
]
==
true
)
{
result
.
add
(
w
);
}
else
{
result
.
add
(
Container
());
}
}
return
result
;
}
@override
Widget
build
(
BuildContext
context
)
{
return
IndexedStack
(
index:
widget
.
currentIndex
,
children:
createChildren
(),
);
}
@override
void
didUpdateWidget
(
covariant
TabPageContainer
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
if
(
oldWidget
.
currentIndex
!=
widget
.
currentIndex
)
{
initMap
[
widget
.
currentIndex
]
=
true
;
setState
(()
{});
}
}
}
lib/main.dart
浏览文件 @
9438de01
...
@@ -5,6 +5,7 @@ import 'package:my_app2/Home/Home.dart';
...
@@ -5,6 +5,7 @@ import 'package:my_app2/Home/Home.dart';
import
'package:my_app2/Mine/Mine.dart'
;
import
'package:my_app2/Mine/Mine.dart'
;
import
'package:my_app2/Network/http/ServiceManager.dart'
;
import
'package:my_app2/Network/http/ServiceManager.dart'
;
import
'package:my_app2/Network/service/XmhService.dart'
;
import
'package:my_app2/Network/service/XmhService.dart'
;
import
'package:my_app2/TabPageContainer.dart'
;
void
main
(
)
{
void
main
(
)
{
runApp
(
const
MyApp
());
runApp
(
const
MyApp
());
...
@@ -57,10 +58,9 @@ class _AppState extends State<App> {
...
@@ -57,10 +58,9 @@ class _AppState extends State<App> {
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
body:
IndexedStack
(
body:
TabPageContainer
(
index:
_currentIndex
,
currentIndex:
_currentIndex
,
children:
const
[
Home
(),
Customization
(),
Mine
()],
children:
const
[
Home
(),
Customization
(),
Mine
()]),
),
bottomNavigationBar:
BottomNavigationBar
(
bottomNavigationBar:
BottomNavigationBar
(
currentIndex:
_currentIndex
,
currentIndex:
_currentIndex
,
items:
const
[
items:
const
[
...
...
pubspec.lock
浏览文件 @
9438de01
...
@@ -185,6 +185,14 @@ packages:
...
@@ -185,6 +185,14 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "5.0.0"
version: "5.0.0"
easy_refresh:
dependency: "direct main"
description:
name: easy_refresh
sha256: "4bf1e3bea60ca21ece286fcde16cdd64bdb7383b4901422a683404f77708c644"
url: "https://pub.dev"
source: hosted
version: "3.3.1"
extended_list_library:
extended_list_library:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -376,6 +384,14 @@ packages:
...
@@ -376,6 +384,14 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "1.0.4"
version: "1.0.4"
nested:
dependency: transitive
description:
name: nested
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
package_config:
package_config:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -392,6 +408,22 @@ packages:
...
@@ -392,6 +408,22 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "1.8.2"
version: "1.8.2"
path_drawing:
dependency: transitive
description:
name: path_drawing
sha256: bbb1934c0cbb03091af082a6389ca2080345291ef07a5fa6d6e078ba8682f977
url: "https://pub.dev"
source: hosted
version: "1.0.1"
path_parsing:
dependency: transitive
description:
name: path_parsing
sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf
url: "https://pub.dev"
source: hosted
version: "1.0.1"
pool:
pool:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -400,6 +432,14 @@ packages:
...
@@ -400,6 +432,14 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "1.5.1"
version: "1.5.1"
provider:
dependency: "direct main"
description:
name: provider
sha256: cdbe7530b12ecd9eb455bdaa2fcb8d4dad22e80b8afb4798b41479d5ce26847f
url: "https://pub.dev"
source: hosted
version: "6.0.5"
pub_semver:
pub_semver:
dependency: transitive
dependency: transitive
description:
description:
...
...
pubspec.yaml
浏览文件 @
9438de01
...
@@ -40,6 +40,8 @@ dependencies:
...
@@ -40,6 +40,8 @@ dependencies:
waterfall_flow
:
any
waterfall_flow
:
any
json_annotation
:
^4.8.0
json_annotation
:
^4.8.0
dio
:
^5.0.0
dio
:
^5.0.0
provider
:
^6.0.5
easy_refresh
:
^3.3.1
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录