Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
netrain_flutter_app
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
邹志胜
netrain_flutter_app
Commits
75beab40
Commit
75beab40
authored
Jul 13, 2021
by
xuehao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gridview
parent
29a1728a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
163 additions
and
71 deletions
+163
-71
main.dart
netrain_flutter_app/lib/main.dart
+8
-2
grid_page.dart
netrain_flutter_app/lib/xuehao/grid_page.dart
+101
-0
list_page.dart
netrain_flutter_app/lib/xuehao/list_page.dart
+54
-69
No files found.
netrain_flutter_app/lib/main.dart
View file @
75beab40
...
...
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:netrain_flutter_app/xuehao/car_details.dart'
;
import
'package:netrain_flutter_app/common/AppColors.dart'
;
import
'package:netrain_flutter_app/xuehao/grid_page.dart'
;
import
'package:netrain_flutter_app/xuehao/list_page.dart'
;
import
'package:netrain_flutter_app/zhangfeng/TestPage.dart'
;
...
...
@@ -53,7 +54,10 @@ class MyApp extends StatelessWidget {
"TestPage"
:
(
context
)
=>
SampleAppPage
(),
"main"
:
(
context
)
=>
mainPage
(),
"firstVC"
:(
context
)
=>
jssPageDemo
(),
"car_details"
:(
context
)
=>
CarDetailsPage
()
"car_details"
:(
context
)
=>
CarDetailsPage
(),
"student"
:(
context
)
=>
jssPageDemo
(),
"car_details"
:(
context
)
=>
CarDetailsPage
(),
"grid_page"
:(
context
)
=>
GridPage
()
},
),
onWillPop:
()
async
{
...
...
@@ -105,7 +109,9 @@ class _RouterNavigatorState extends State<RouterNavigator> {
_item
(
"登录网络请求"
,
LoginRequestPage
(),
'LoginRequestPage'
),
_item
(
"zhangfengTest页面"
,
List_Page
(),
'TestPage'
),
_item
(
"listview页面"
,
List_Page
(),
'listPage'
),
_item
(
"jssDemo"
,
jssPageDemo
(),
'firstVC'
)
_item
(
"jssDemo"
,
jssPageDemo
(),
'firstVC'
),
_item
(
"jssDemo"
,
jssPageDemo
(),
'student'
),
_item
(
"gridView"
,
GridPage
(),
'grid_page'
)
],
),
);
...
...
netrain_flutter_app/lib/xuehao/grid_page.dart
0 → 100644
View file @
75beab40
import
'dart:ffi'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_easyrefresh/easy_refresh.dart'
;
/**
* @author xuehao
* on 2021/7/13
*/
class
GridPage
extends
StatefulWidget
{
GridPage
({
Key
key
})
:
super
(
key:
key
);
@override
_GridPageState
createState
()
=>
_GridPageState
();
}
class
_GridPageState
extends
State
<
GridPage
>
{
EasyRefreshController
_controller
=
EasyRefreshController
();
@override
Widget
build
(
BuildContext
context
)
{
return
new
MaterialApp
(
title:
"grid_page"
,
home:
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"grid_page"
),
),
body:
EasyRefresh
(
controller:
_controller
,
header:
MaterialHeader
(),
footer:
PhoenixFooter
(),
onRefresh:
()
async
{
_refresh
();
},
onLoad:
()
async
{
_loadData
();
},
child:
GridView
.
builder
(
///GridView配置项
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount
(
//设置每行最大显示数量
crossAxisCount:
3
,
//横轴间距
crossAxisSpacing:
2.0
,
//主轴间距
mainAxisSpacing:
2.0
,
//宽高比
childAspectRatio:
0.7
,
),
itemCount:
_datas
.
length
,
itemBuilder:
(
context
,
index
)
{
return
_itemWidget
(
_datas
[
index
]);
},
),
),
),
);
}
List
<
String
>
_datas
=
[
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
,
];
Future
<
void
>
_refresh
()
async
{
Future
.
delayed
(
Duration
(
seconds:
2
),
()
async
{
setState
(()
{
for
(
int
i
=
0
;
i
<
_datas
.
length
;
i
++)
{
_datas
[
i
]
=
"https://img2.baidu.com/it/u=1852546487,3301595200&fm=11&fmt=auto&gp=0.jpg"
;
}
_controller
.
finishRefresh
(
success:
true
);
});
});
}
Future
<
void
>
_loadData
()
async
{
Future
.
delayed
(
Duration
(
seconds:
2
),
()
async
{
setState
(()
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
_datas
.
add
(
"https://img1.baidu.com/it/u=4241162085,3588743387&fm=26&fmt=auto&gp=0.jpg"
);
}
_controller
.
finishLoad
(
success:
true
);
});
});
}
Widget
_itemWidget
(
String
src
)
{
return
new
Image
.
network
(
src
,
fit:
BoxFit
.
cover
);
}
}
netrain_flutter_app/lib/xuehao/list_page.dart
View file @
75beab40
...
...
@@ -56,23 +56,60 @@ class _ListPageState extends State<List_Page> with WidgetsBindingObserver {
);
}
void
dispose
()
{
super
.
dispose
();
WidgetsBinding
.
instance
.
removeObserver
(
this
);
print
(
"dispose"
);
}
//定义一个全局的变量:模型数组
List
<
Car
>
datas
=
[
Car
(
name:
'保时捷918 Spyder'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-7d8be6ebc4c7c95b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'兰博基尼Aventador'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-e3bfd824f30afaac?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'法拉利Enzo'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-a1d64cf5da2d9d99?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'Zenvo ST1'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-bf883b46690f93ce?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'迈凯伦F1'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-5a7b5550a19b8342?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'萨林S7'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-2e128d18144ad5b8?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'科尼赛克CCR'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-01ced8f6f95219ec?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'布加迪Chiron'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-7fc8359eb61adac0?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'轩尼诗Venom GT'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-d332bf510d61bbc2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'西贝尔Tuatara'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-3dd9a70b25ae6bc9?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
)
];
@override
void
initState
()
{
super
.
initState
();
WidgetsBinding
.
instance
.
addObserver
(
this
);
print
(
"initState"
);
}
@override
void
didChangeAppLifecycleState
(
AppLifecycleState
state
)
{
print
(
state
);
}
///获取item视图
Widget
_getDatas
(
int
position
)
{
...
...
@@ -131,56 +168,4 @@ class _ListPageState extends State<List_Page> with WidgetsBindingObserver {
}
}
//定义一个全局的变量:模型数组
List
<
Car
>
datas
=
[
Car
(
name:
'保时捷918 Spyder'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-7d8be6ebc4c7c95b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'兰博基尼Aventador'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-e3bfd824f30afaac?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'法拉利Enzo'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-a1d64cf5da2d9d99?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'Zenvo ST1'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-bf883b46690f93ce?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'迈凯伦F1'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-5a7b5550a19b8342?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'萨林S7'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-2e128d18144ad5b8?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'科尼赛克CCR'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-01ced8f6f95219ec?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'布加迪Chiron'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-7fc8359eb61adac0?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'轩尼诗Venom GT'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-d332bf510d61bbc2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
),
Car
(
name:
'西贝尔Tuatara'
,
imageUrl:
'https://upload-images.jianshu.io/upload_images/2990730-3dd9a70b25ae6bc9?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
,
)
];
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