Flutter
- 概要:
- 单页时FlexList, 去调系统外边界 的界面边界,与内容最小边界 取大。 然后和内容最大边界取小。
- 内部时, 界面边界,与内容最小边界 取大。 此时的界面边界 是按机型来的。 比如 N5, 取220, A3,取240. 2的问题,开发时需要 开发者计算边界, 没有想 好如何自动算出来。
- 场景:
小机型 无法一页显示,要滑动。
或关键内容在下一个可见区域
- 代码:
import 'dart:math';
import 'package:flutter/material.dart';
class FlexList extends StatelessWidget {
const FlexList(
{Key key,
this.minHigh,
this.maxHigh = double.infinity,
this.appBar,
this.backgroundColor,
this.children})
:
super(key: key)
;
final double minHigh;
final double maxHigh;
final PreferredSizeWidget appBar;
final Color backgroundColor;
final List<Widget> children;
@override
Widget build(BuildContext context) {
double contextHight = MediaQuery.of(context).size.height -
MediaQuery.of(context).viewPadding.top -
(appBar != null ? 0 : kToolbarHeight);
debugPrint(contextHight.toString());
return ListView(children: <Widget>[
Container(
height: min( max(contextHight, minHigh), maxHigh) +
MediaQuery.of(context).viewInsets.bottom,
child: Scaffold(
appBar: appBar,
backgroundColor: backgroundColor ?? Colors.transparent,
body: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Column(
// mainAxisSize: minHigh > contextHight ? MainAxisSize.min : MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: children,
),
)),
)
]);
}
}
重点:
mainAxisAlignment: MainAxisAlignment.spaceAround,