Skip to content

Instantly share code, notes, and snippets.

@CMingTseng
Created December 2, 2021 09:36
Show Gist options
  • Save CMingTseng/3bae7ed37447b63ced0487b360cb0fba to your computer and use it in GitHub Desktop.
Save CMingTseng/3bae7ed37447b63ced0487b360cb0fba to your computer and use it in GitHub Desktop.
class ItemBuildModify extends StatelessWidget {
final Color color;
ItemBuildModify(this.color );
@override
Widget build(BuildContext context) {
////TODO below fail !! if use Scaffold will get Height infinity error
return
// Scaffold(
// body:
SafeArea(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child:
Container(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height,
maxHeight: MediaQuery.of(context).size.height*2,
minWidth: MediaQuery.of(context).size.width,
maxWidth: MediaQuery.of(context).size.width*2,
),
//height:MediaQuery.of(context).size.height,
color: color,
// child: MyDefine(),//<-- Here use my layout
)
)
)
// )
;
}
}
class ItemSizeCheck extends StatelessWidget {
final Color color;
ItemSizeCheck(this.color );
@override
Widget build(BuildContext context) {
//// it is ok
return Container(
//TODO must BoxConstraints !! if not this item cannot show
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height/3,
maxHeight: MediaQuery.of(context).size.height*2,
minWidth: MediaQuery.of(context).size.width/3,
maxWidth: MediaQuery.of(context).size.width*2,
),
// height:MediaQuery.of(context).size.height,
color: color,
);
}
}
class ControllerDemoPage extends StatelessWidget {
//https://www.kindacode.com/article/ways-to-create-random-colors-in-flutter/
// This holds the items of the ListView
final _listItems = List.generate(200, (i) => "Item $i");
// Used to generate random integers
final _random = Random();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"ControllerDemoPage",
),
),
body:ListView.separated(
scrollDirection: Axis.vertical,
separatorBuilder: (BuildContext ctx, int index) {
return SizedBox(
width: 10,
height: 10,
);
},
// itemCount: _listItems.length,
itemCount: 30,
// itemBuilder: (BuildContext ctx, int index) {
itemBuilder: (_, index) {
return ItemSizeCheck(Color.fromARGB(_random.nextInt(256-index), _random.nextInt(256+index), _random.nextInt(256+index), _random.nextInt(256-index))) ;
// return return ItemBuildModify(Color.fromARGB(_random.nextInt(256-index), _random.nextInt(256+index), _random.nextInt(256+index), _random.nextInt(256-index))) ;
})
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment