Commit 2a777710 authored by jishuaishuai's avatar jishuaishuai

listview练习 刷新练习

parent e185390e
import 'package:flutter/material.dart';
class fifthDemo extends StatefulWidget {
fifthDemo({Key key}) : super(key: key);
@override
_fifthDemoState createState() {
return _fifthDemoState();
}
}
class _fifthDemoState extends State<fifthDemo> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("第五个页面"),
),
body: fifthListViewDemo(),
);
}
}
class fifthListViewDemo extends StatefulWidget {
fifthListViewDemo({Key key}) : super(key: key);
@override
_fifthListViewDemoState createState() {
return _fifthListViewDemoState();
}
}
class _fifthListViewDemoState extends State<fifthListViewDemo> {
List<int>listArr = List();
@override
void initState() {
super.initState();
for(var i = 0; i<100 ;i++){
listArr.add(i);
}
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scrollbar(
child: RefreshIndicator(
child: ListView.builder(itemBuilder:(BuildContext context, int index){
if (index == 2) {
}
return Container(
child: Flex(
children: [
Text(listArr[index].toString()),
ElevatedButton(onPressed: (){
print("点击了");
}, child:Text("我是个按钮") ),
Container(
width: 100,
height: 300,
color: Colors.orange,
)
],
),
);
}),
),
);
}
Future _onRefresh() async {
await Future.delayed(
Duration(seconds: 2),
() {
print("object");
},
);
return "";
}
}
\ No newline at end of file
...@@ -3,6 +3,8 @@ import 'package:netrain_flutter_app/common/Images.dart'; ...@@ -3,6 +3,8 @@ import 'package:netrain_flutter_app/common/Images.dart';
import 'secondVC.dart'; import 'secondVC.dart';
class jssPageDemo extends StatelessWidget { class jssPageDemo extends StatelessWidget {
// const ({Key? key}) : super(key: key) // const ({Key? key}) : super(key: key)
...@@ -91,14 +93,17 @@ class buttonDemo extends StatelessWidget { ...@@ -91,14 +93,17 @@ class buttonDemo extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
children: [ children: [
//改用ElevatedButton
RaisedButton( RaisedButton(
onPressed: (){}, onPressed: (){},
child:Text("漂浮按钮") child:Text("漂浮按钮")
), ),
//改用 TextButton
FlatButton( FlatButton(
onPressed: (){}, onPressed: (){},
child: Text("扁平按钮") child: Text("扁平按钮")
), ),
//改用 TextButton
FlatButton.icon( FlatButton.icon(
onPressed: (){}, onPressed: (){},
icon: Icon(Icons.outbound), icon: Icon(Icons.outbound),
...@@ -106,6 +111,7 @@ class buttonDemo extends StatelessWidget { ...@@ -106,6 +111,7 @@ class buttonDemo extends StatelessWidget {
color: Colors.black, color: Colors.black,
textColor: Colors.white, textColor: Colors.white,
), ),
//改用 OutlinedButton
OutlineButton(onPressed: (){}, OutlineButton(onPressed: (){},
child: Text("边框按钮"), child: Text("边框按钮"),
), ),
......
import 'package:flutter/material.dart';
class fourthDemo extends StatefulWidget {
fourthDemo({Key key}) : super(key: key);
@override
_fourthDemoState createState() {
return _fourthDemoState();
}
}
class _fourthDemoState extends State<fourthDemo> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("jss测试第四个页面"),
),
body: someDemo());
}
}
class someDemo extends StatefulWidget {
someDemo({Key key}) : super(key: key);
@override
_someDemoState createState() {
return _someDemoState();
}
}
class _someDemoState extends State<someDemo> {
List<int> listArrData = List();
@override
void initState() {
super.initState();
for (var i = 0; i < 100; i++) {
listArrData.add(i);
}
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scrollbar(
child: RefreshIndicator(
child: ListView(
//y轴
scrollDirection: Axis.vertical,
children: listArrData
.map((e) => Container(
width: 200,
height: 100,
child: Flex(
direction: Axis.vertical,
children: [
Text(e.toString()),
ElevatedButton(
onPressed: () {
},
child: Text("点击进入第5个页面"))
],
),
decoration: BoxDecoration(
color: Colors.red,
),
//旋转跳跃我闭着眼
// transform: Matrix4.rotationZ(0.5),
))
.toList(),
),
onRefresh: _onRefresh,
));
}
Future _onRefresh() async {
await Future.delayed(
Duration(seconds: 2),
() {
print("object");
},
);
return "";
}
}
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:netrain_flutter_app/common/Images.dart'; import 'package:netrain_flutter_app/common/Images.dart';
import 'thirdVC.dart'; import 'thirdVC.dart';
class twoVCdemo extends StatelessWidget { class twoVCdemo extends StatelessWidget {
// const ({Key? key}) : super(key: key); // const ({Key? key}) : super(key: key);
...@@ -12,20 +11,21 @@ class twoVCdemo extends StatelessWidget { ...@@ -12,20 +11,21 @@ class twoVCdemo extends StatelessWidget {
appBar: AppBar( appBar: AppBar(
title: Text("jssDemo第二个页面的标题"), title: Text("jssDemo第二个页面的标题"),
), ),
body: Column( body: Column(
children: [ children: [
ElevatedButton( ElevatedButton(
child: Text("第二页面的按钮,跳转带参数过去"), child: Text("第二页面的按钮,跳转带参数过去"),
onPressed:() { onPressed: () {
Navigator.of(context).push(MaterialPageRoute( Navigator.of(context).push(MaterialPageRoute(
builder: (context){ builder: (context) {
return nextViewDemo(); return nextViewDemo();
}, },
settings: RouteSettings( settings: RouteSettings(
name: "我是传过去的", name: "我是传过去的",
arguments:"参数,是对象类型", arguments: "参数,是对象类型",
), ),
//是否有返回 //是否有返回
maintainState: false, maintainState: false,
...@@ -35,12 +35,12 @@ class twoVCdemo extends StatelessWidget { ...@@ -35,12 +35,12 @@ class twoVCdemo extends StatelessWidget {
); );
}, },
), ),
Flex(direction:Axis.horizontal,
children: [
Image.asset(Images.ic_home_normal,alignment: Alignment.center,),
Flex(
direction: Axis.horizontal,
children: [
Image.asset(Images.ic_home_normal, alignment: Alignment.center,),
], ],
) )
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:netrain_flutter_app/jishuaishuai/fourthVC.dart';
class nextViewDemo extends StatelessWidget { class nextViewDemo extends StatelessWidget {
...@@ -7,13 +8,16 @@ class nextViewDemo extends StatelessWidget { ...@@ -7,13 +8,16 @@ class nextViewDemo extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: Colors.black26,
appBar: AppBar( appBar: AppBar(
title: Text("jss测试第三界面"), title: Text("jss测试第三界面"),
), ),
body: Column( body: Container(
child: Flex(
direction: Axis.vertical,
children: [ children: [
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -23,11 +27,132 @@ class nextViewDemo extends StatelessWidget { ...@@ -23,11 +27,132 @@ class nextViewDemo extends StatelessWidget {
}, },
child: Text("点击返回传值"), child: Text("点击返回传值"),
), ),
ElevatedButton(onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder:(context){
return fourthDemo();
},
settings: RouteSettings(
name: "thirdVC"
)
)
);
}, child: Container(
child: Text("点击进入第四个页面"),
)
),
listViewDemo(),
WarpDemo(),
],
),
)
);
}
}
class listViewDemo extends StatefulWidget {
listViewDemo({Key key}) : super(key: key);
@override
_listViewDemoState createState() {
return _listViewDemoState(
);
}
}
class _listViewDemoState extends State<listViewDemo> {
@override
void initState() {
super.initState();
//创建时
}
@override
void dispose() {
//销毁时
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Container(
width: 600,
height: 300,
color: Colors.grey,
child:Align(
alignment:Alignment(-0.5,0.5),
child: Stack(
alignment: AlignmentDirectional.topStart,
children: [
Container(
width: 100,
height: 100,
color: Colors.orange,
),
Positioned(
left: 20,
right: 30,
top: 10,
bottom: 20,
child: Container(
color: Colors.red,
)),
], ],
), ),
)
);
}
}
class WarpDemo extends StatefulWidget {
WarpDemo({Key key}) : super(key: key);
@override
_WarpDemoState createState() {
return _WarpDemoState();
}
}
class _WarpDemoState extends State<WarpDemo> {
List<int>listArr = List();
@override
void initState() {
super.initState();
for(var i = 0;i < 10;i++){
listArr.add(i);
}
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Wrap(
// spacing: 10.0,
runAlignment: WrapAlignment.center,
// runSpacing: 1,
children: listArr.map((e) => Container(
height: 100,
width: 100,
child: Text(e.toString()),
color: Colors.blue,
)).toList(
)
); );
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment