Flutter这么火为什么不了解一下呢?(下,Android基础面试常常死在这几个问题上

Icons.star,
color: Colors.red[500],
),
new Text(‘41’),
],
),
);
//…
}

Tip: 粘贴代码到工程中时,代码缩进可能错乱。如果是在IntelliJ中,可以有单机选择Reformat with Dart Style。或者在命令行中使用dartfmt命令。

Tip: 为体验更快开发过程,尝试使用Flutter的热加载功能。热加载使得在修改代码同时快速地在查看到修改后的效果,而不用重运行app。

##Step 3:实现按钮行(Button Section)

Button Section包含3列相同的布局——一个图标和一个文本。这行中3列均匀分布,并且文本和图标颜色是APP build()方法中设置的primary color。

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// title section implementation

return new MaterialApp(
title: ‘Flutter Demo’,
theme: new ThemeData(
primarySwatch: Colors.blue,
),

//…
}

由于创建每列的代码是相同的,最高效的办法就是创建一个嵌套函数,例如就定义为buildButtonColumn(),这个方法中创建包含一个图标和一个文本得组件,并且返回Column对象。

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
//…

Column buildButtonColumn(IconData icon, String label) {
Color color = Theme.of(context).primar

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

yColor;

return new Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Icon(icon, color: color),
new Container(
margin: const EdgeInsets.only(top: 8.0),
child: new Text(
label,
style: new TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w400,
color: color,
),
),
),
],
);
}
//…
}

这个创建方法中直接添加icon组件。将文本组件放于Container组件中来添加上边距,将icon与text分离开。

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
//…

Widget buttonSection = new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildButtonColumn(Icons.call, ‘CALL’),
buildButtonColumn(Icons.near_me, ‘ROUTE’),
buildButtonColumn(Icons.share, ‘SHARE’),
],
),
);
//…
}

##Step 4:实现多行文本(Text Section)

由于文本太长,其实现我们赋值于一个变量。将文本放在Container中,四周边距设置32px。设置softwrap属性,这个属性表示当每行文本遇到句号或者逗号时是否需要换行。

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
//…

Widget textSection = new Container(
padding: const EdgeInsets.all(32.0),
child: new 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,
),
);
//…
}

##Step 5:实现头部图片(Image Section)

目前只剩头部图片部分还未实现。这张图片基于Creative Commons协议在网上是可以获取到的(当然学习过程,可以自己比较随意的拿一张图片进行)。由于图片较大且网络加载慢,所以在Step 0步骤中已经inlude进来并且修改了pubspec.yml文件,可以直接在本地进行访问。

body: new ListView(
children: [
new Image.asset(
‘images/lake.jpg’,
height: 240.0,
fit: BoxFit.cover,
),
// …
],
)

BoxFit.cover 告诉Framework图片需要尽可能的小但是需要充满显示部分。

##Step 6:整合

最后一步,将删除个步骤中定义的组件最终整合在一起。所有组件放置于ListView中。

import ‘package:flutter/material.dart’;

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget titleSection = new Container(
padding: const EdgeInsets.all(32.0),
child: new Row(
children: [
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
new Container(
padding: new EdgeInsets.only(bottom: 8.0),
child: new Text(
‘Oeschinec lake Compground’,
style: new TextStyle(fontWeight: FontWeight.bold),
),
),
new Text(
‘Kandersteg, Switzerland’,
style: new TextStyle(color: Colors.grey[500]),
),
],
)),
new Icon(
Icons.star,
color: Colors.red[500],
),
new Text(‘41’)
],
),
);

// button section
Column buildButtonColumn(IconData icon, String label) {
Color color = Theme.of(context).primaryColor;

return new Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
new Icon(icon, color: color),
new Container(
margin: const EdgeInsets.only(top: 8.0),
child: new Text(
label,
style: new TextStyle(
color: color,
fontSize: 12.0,
fontWeight: FontWeight.w400,
),
),
),
],
);
}

Widget buttonSection = new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildButtonColumn(Icons.call, ‘CALL’),
buildButtonColumn(Icons.near_me, ‘ROUTE’),
buildButtonColumn(Icons.share, ‘SHARE’),
],
),
);

Widget textSection = new Container(
padding: const EdgeInsets.all(32.0),
child: new 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,
),
);

return new MaterialApp(
title: ‘Flutter Demo’,
theme: new ThemeData(primarySwatch: Colors.blue),
home: new Scaffold(
appBar: new AppBar(
title: new Text(‘Top Lakes’),
),
body: new ListView(
children: [
new Image.asset(
‘images/lake.jpg’,
height: 240.0,
fit: BoxFit.cover,
),
titleSection,
buttonSection,
textSection,
],
),
),
);
}
}

##喜欢的话请帮忙转发一下能让更多有需要的人看到吧。有些技术上的问题大家可以多探讨一下,谢谢!
以下为部分高级技术体系。需要一份最新Android高级架构技术体系大纲以及全部视频资料的可以转发后私信找我领取

领取方式:转发+关注。私信我,领取资料。 即可前往免费领取!!!

nSection,
textSection,
],
),
),
);
}
}

##喜欢的话请帮忙转发一下能让更多有需要的人看到吧。有些技术上的问题大家可以多探讨一下,谢谢!
以下为部分高级技术体系。需要一份最新Android高级架构技术体系大纲以及全部视频资料的可以转发后私信找我领取
[外链图片转存中…(img-QveSl6rz-1640240160122)]

领取方式:转发+关注。私信我,领取资料。 即可前往免费领取!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值