【Flutter&Dart】构建结构(1/100)

打印 上一主题 下一主题

主题 1082|帖子 1082|积分 3256

构建结构


没什么好先容的,训练构建而已;代码如下:
  1. //绘制布局图
  2. import 'package:flutter/material.dart';
  3. class MyApp1 extends StatelessWidget {
  4.   @override
  5.   Widget build(BuildContext context) {
  6.     Widget titleSection = Container(
  7.       padding: const EdgeInsets.all(32.0),
  8.       child: Row(
  9.         children: [
  10.           Expanded(
  11.               child: Column(
  12.             crossAxisAlignment: CrossAxisAlignment.start,
  13.             children: [
  14.               Container(
  15.                 padding: const EdgeInsets.only(bottom: 8.0),
  16.                 child: Text(
  17.                   'Oeschinen Lake Campground',
  18.                   style: TextStyle(fontWeight: FontWeight.bold),
  19.                 ),
  20.               ),
  21.               Text(
  22.                 'Kandersteg, Switzerland',
  23.                 style: TextStyle(
  24.                   color: Colors.grey[500],
  25.                 ),
  26.               )
  27.             ],
  28.           )),
  29.           Icon(
  30.             Icons.star,
  31.             color: Colors.red[500],
  32.           ),
  33.           Text('41'),
  34.         ],
  35.       ),
  36.     );
  37.     Column buildButtonColumn(IconData icon, String label) {
  38.       Color color = Theme.of(context).primaryColor;
  39.       return Column(
  40.         mainAxisSize: MainAxisSize.min,
  41.         mainAxisAlignment: MainAxisAlignment.center,
  42.         children: [
  43.           Icon(
  44.             icon,
  45.             color: color,
  46.           ),
  47.           Container(
  48.             margin: const EdgeInsets.only(top: 8.0),
  49.             child: Text(
  50.               label,
  51.               style: TextStyle(
  52.                   fontSize: 12.0, fontWeight: FontWeight.w400, color: color),
  53.             ),
  54.           )
  55.         ],
  56.       );
  57.     }
  58.     Widget buttonSection = Container(
  59.       child: Row(
  60.         mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  61.         children: [
  62.           buildButtonColumn(Icons.call, 'CALL'),
  63.           buildButtonColumn(Icons.near_me, 'ROUTE'),
  64.           buildButtonColumn(Icons.share, 'SHARE'),
  65.         ],
  66.       ),
  67.     );
  68.     Widget textSection = Container(
  69.       padding: const EdgeInsets.all(32.0),
  70.       child: Text(
  71.         '''
  72. 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.
  73.         ''',
  74.         softWrap: true,
  75.       ),
  76.     );
  77.     return MaterialApp(
  78.       title: 'Flutter Demo',
  79.       theme: ThemeData(
  80.         primarySwatch: Colors.blue,
  81.       ),
  82.       home: Scaffold(
  83.         body: ListView(
  84.           children: [
  85.             Image.asset(
  86.               'images/smart_api.png',
  87.               height: 240.0,
  88.               fit: BoxFit.cover,
  89.             ),
  90.             titleSection,
  91.             buttonSection,
  92.             textSection,
  93.           ],
  94.         ),
  95.       ),
  96.     );
  97.   }
  98. }
复制代码
main.dart 入口调用如下:
  1. import 'w3c/MyApp1.dart';
  2. void main() {
  3. //MyApp1
  4.   runApp(MyApp1());
  5.   }
复制代码
如果说还有啥,就是一点点设置了:
在 pubspec.yaml 里设置 assets images 资源图片
  1. # The following section is specific to Flutter packages.
  2. flutter:
  3.   # The following line ensures that the Material Icons font is
  4.   # included with your application, so that you can use the icons in
  5.   # the material Icons class.
  6.   uses-material-design: true
  7.   # To add assets to your application, add an assets section, like this:
  8.   assets:
  9.     # - images/a_dot_burr.jpeg
  10.     # - images/a_dot_ham.jpeg
  11.     - images/smart_api.png
复制代码
还有就是在工程根目录预备 images 图片文件夹存放图片,如下图:

============END
如果对老师您有点用,用您发财的金手指点个赞

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

宁睿

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表