Flutter 布局学习
https://flutter.dev/docs/development/ui/layout/tutorial
为了让例子运行起来,需要将 图片 保存在项目的 images 目录下,在 pubspec.yaml 增加如下配置:
uses-material-design: true
+ assets: [
+ images/lake.jpg
+ ]
+
另,教程上的 assets 的写法有是没有 []
括起来会导致报错。下面例子中 _buildButtonColumn
中无法传入 color,因为 color 依赖于 context,因此下面的实现移除掉了 color。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
Widget titleSection = Container(
padding: const EdgeInsets.all(32),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
'Oeschinen Lake Campground',
style: TextStyle(
fontWeight: FontWeight.bold
)
)
),
Text(
'Kandersteg, Switzerland',
style: TextStyle(
color: Colors.grey[500]
)
)
],
)
),
Icon(
Icons.star,
color: Colors.red[500]
),
Text('41')
]
)
);
Column _buildButtonColumn(IconData icon, String label) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon),
Container(
margin: const EdgeInsets.only(top: 8),
child: Text(
label,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
)
)
)
]
);
}
// Color color = Theme.of(context).primaryColor;
Widget buttonSection = Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_buildButtonColumn(Icons.call, 'CALL'),
_buildButtonColumn(Icons.near_me, 'ROUTE'),
_buildButtonColumn(Icons.share, 'SHARE'),
],
)
);
Widget textSection = Container(
padding: const EdgeInsets.all(32),
child: Text(
'Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese '
'Alps. Situated 1,578 meters above sea level, it is one of the '
'larger Alpine Lakes. A gondola ride from Kandersteg, followed by a '
'half-hour walk through pastures and pine forest, leads you to the '
'lake, which warms to 20 degrees Celsius in the summer. Activities '
'enjoyed here include rowing, and riding the summer toboggan run.',
softWrap: true
)
);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter layout demo',
home: Scaffold(
appBar: AppBar(
title: Text('Flutter layout demo'),
),
body: ListView(
children: [
Image.asset(
'images/lake.jpg',
width: 600,
height: 240,
fit: BoxFit.cover
),
titleSection,
buttonSection,
textSection
]
)
),
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论