Skip to content

Instantly share code, notes, and snippets.

@CMingTseng
Created December 2, 2021 03:26
Show Gist options
  • Save CMingTseng/aee0ab51844efab56ed2b3201165c6e2 to your computer and use it in GitHub Desktop.
Save CMingTseng/aee0ab51844efab56ed2b3201165c6e2 to your computer and use it in GitHub Desktop.
ScrollViewItemChildSize.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
class ItemSizeCheck extends StatelessWidget {
final Color color;
ItemSizeCheck(this.color );
@override
Widget build(BuildContext context) {
return Container(
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 {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"ControllerDemoPage",
),
),
body:
SingleChildScrollView(
child: Column(
children: [
//問題 這個 Container 的 Height 好像才是限制 child item的 ?
// 我該如何 設置 child item ? 讓child item "單一個" 就滿版(占用除去toolbar之外全部空間) ?
Container(
constraints: BoxConstraints(minHeight: MediaQuery.of(context).size.height, maxHeight:10*MediaQuery.of(context).size.height),
child: Column(mainAxisSize: MainAxisSize.max,
children: [
Flexible(
flex: 1,
child: ItemSizeCheck(Colors.yellow)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.brown)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.green,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.red,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.yellow,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck(Colors.brown,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.green,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck(Colors.red,
)
),Flexible(
flex: 1,
child: ItemSizeCheck( Colors.yellow,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.brown,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.green,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.red,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.yellow,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck(Colors.brown,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.green,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck(Colors.red,
)
),
Flexible(
flex: 1,
child: ItemSizeCheck( Colors.yellow,
)
),
Flexible(
flex: 1,
child:ItemSizeCheck(Colors.brown,
)
),
Flexible(
flex: 1,
child:ItemSizeCheck( Colors.green,
)
),
Flexible(
flex: 1,
child:ItemSizeCheck( Colors.red,
)
),
],
),
),
],
)
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment