|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +class Index extends StatefulWidget { |
| 4 | + @override |
| 5 | + _IndexState createState() => _IndexState(); |
| 6 | +} |
| 7 | + |
| 8 | +class _IndexState extends State<Index> { |
| 9 | + var height = 360.0; |
| 10 | + |
| 11 | + @override |
| 12 | + Widget build(BuildContext context) { |
| 13 | + return Scaffold( |
| 14 | + appBar: AppBar(title: Text('LayoutBuilder'),), |
| 15 | + body: ListView( |
| 16 | + children: <Widget>[ |
| 17 | + InkWell( |
| 18 | + onTap: () { |
| 19 | + this.setState(() { |
| 20 | + height == 360.0 ? height = 200.0 : height = 360.0; |
| 21 | + }); |
| 22 | + }, |
| 23 | + child: Text('父视口高度: $height', style: TextStyle(fontSize: 16.0),), |
| 24 | + ), |
| 25 | + Container( |
| 26 | + width: double.infinity, |
| 27 | + height: height, |
| 28 | + color: Colors.blueGrey, |
| 29 | + margin: EdgeInsets.only(top: 10.0), |
| 30 | + child: LayoutBuilder( |
| 31 | + builder: (BuildContext context, BoxConstraints viewportConstraints) { |
| 32 | + return SingleChildScrollView( |
| 33 | + child: ConstrainedBox( |
| 34 | + constraints: |
| 35 | + BoxConstraints(minHeight: viewportConstraints.maxHeight), |
| 36 | + child: Column( |
| 37 | + mainAxisSize: MainAxisSize.min, |
| 38 | + mainAxisAlignment: MainAxisAlignment.spaceAround, |
| 39 | + children: <Widget>[ |
| 40 | + Container( |
| 41 | + child: Image.network('http://pic1.win4000.com/wallpaper/2019-02-15/5c664c3e1d90c.jpg', fit: BoxFit.cover,), |
| 42 | + height: 120, |
| 43 | + width: double.infinity, |
| 44 | + ), |
| 45 | + Container( |
| 46 | + child: Image.network('http://pic1.win4000.com/wallpaper/2019-02-15/5c664c48c73d0.jpg', fit: BoxFit.cover,), |
| 47 | + height: 160, |
| 48 | + width: double.infinity, |
| 49 | + ) |
| 50 | + ], |
| 51 | + ), |
| 52 | + ), |
| 53 | + ); |
| 54 | + } |
| 55 | + ), |
| 56 | + ) |
| 57 | + ], |
| 58 | + ) |
| 59 | + ); |
| 60 | + } |
| 61 | +} |
0 commit comments