flutterchina / flutter_in_action_2nd Goto Github PK
View Code? Open in Web Editor NEW《Flutter实战 第二版》 书稿
Home Page: https://book.flutterchina.club/
《Flutter实战 第二版》 书稿
Home Page: https://book.flutterchina.club/
// 弹出对话框
// >>> update <<<
Future<bool?> showDeleteConfirmDialog1(BuildContext context) {
return showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
title: Text("提示"),
content: Text("您确定要删除当前文件吗?"),
actions: <Widget>[
TextButton(
child: Text("取消"),
onPressed: () => Navigator.of(context).pop(), // 关闭对话框
),
TextButton(
child: Text("删除"),
onPressed: () {
//关闭对话框并返回true
Navigator.of(context).pop(true);
},
),
],
);
},
);
}
在“1.1.5 Flutter出世”处有一段文字“国内外有非常基于 Flutter 的成功案例”,这句话有语病
什么是“编译类语言的执行同城”
应该是“编译类语言的执行方式通常”吧
你好,我在学习的过程中,发现在2.2.4 StatelessWidget中,显示Echo这个widget,书中的代码是
Widget build(BuildContext context) {
return Echo(text: "hello world");
}
但是这样子不是就没有了"AppBar"这些元素了,是不是缺了哪些上下文?
直接使用代码会报以下错误:
Cannot hit test a render box with no size.
需要给Container加上个高度可解决。
return Container(
alignment: Alignment.center,
height: 500,
child: FutureBuilder(
var t; // 由于没有对 t 进行初始化,此时 t 的类型为:dynamic,所以对后续赋值没有限制
t = "hi wendux"; // 正确(因为 t 是 dynamic 类型的)
t = 1000; // 正确(因为 t 是 dynamic 类型的)
t = true; // 正确(因为 t 是 dynamic 类型的)
场景二:
var t = "hi wendux"; // 由于初始化了 t,此时 t 的类型为 String,不可再用其他类型数据进行赋值
t = "hello wendux"; // 正确(因为 t 是 String 类型的)
t = 1000; // 错误(因为 t 是 String 类型的)
t = true; // 错误(因为 t 是 String 类型的)
版本相关信息:
Flutter 2.5.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ffb2ecea52 (12 天前) • 2021-09-17 15:26:33 -0400
Engine • revision b3af521a05
Tools • Dart 2.14.2
var item = buildItem(context, index);
data.removeAt(index);
print('删除 ${data[index]}');
Should be changed to
var item = buildItem(context, index);
print('删除 ${data[index]}');
data.removeAt(index);
示例代码 在2.8版本下无法运行
部份文本仍然使用過時的widgets
在7.3 Provider 章節中,使用的都是RaisedButton。
https://github.com/flutterchina/flutter_in_action_2nd/blob/main/src/chapter7/provider.md
在 6.3 章节介绍 ListView 的 prototypeItem 时结尾多了“如果”两个字
看完作者的解释还是不能明白,为什么不把state和build都放在widget中?更新状态仍然可以使用setState方法。为了维护状态专门新建一个state类有必要吗?
很多书籍都有私利代码的下载,为何不提供楠?
第三章目录
3.1:Widget简介
3.2:状态管理
缺少对应章节
3.5 FocusScopeNode focusScopeNode;必须初始化 然后RaisdButton在2.5.0版本就被废弃了 。
然后需要一个父组件
The following assertion was thrown building TextField(focusNode: FocusNode#5550e, decoration: InputDecoration(labelText: "input2"), dirty, dependencies: [MediaQuery, UnmanagedRestorationScope], state: _TextFieldState#72f17): No Material widget found.
为控制焦点部分
更新2.5.0版本后很多错误了 希望改正
定义函数时,可选的位置参数和命名可选参数,需要再类型前加 ?。或者给参数设置默认值
例子:
void say(name, {int age = 0, double? height = 0.0}) {
print("name is $name, age is $age and height is $height");
}
void sayHello(name, [int? age = 0, double height = 0.0]) {
print("name is $name, age is $age and height is $height");
}
你好,我在学习的过程中,发现在2.2.4 StatelessWidget中,显示Echo这个widget,书中的代码是
Widget build(BuildContext context) {
return Echo(text: "hello world");
}
但是这样子不是就没有了"AppBar"这些元素了,是不是缺了哪些上下文?或者是这段代码应该写在哪个位置?
坐标:9.4 Hero动画,HeroAnimationRoute作为一个单独页面运行的时候会报错,需要将build下return的根节点改为Scaffold才能运行通过,sdk: flutter2.5
10.8.3文本水印画笔:
1、TextWaterMarkPainter 缺少 textDirection 属性对象
2、绘制文本 _textStyle 缺少 _handleTextStyle 方法
章末缺少完整实例,文章代码有点混乱
偏后部分的 而术语 **DOM操作 **就是指
应改为 而术语 **DOM操作**就是指
解释执行是不是更好一点?
typedef SliverHeaderBuilder = Widget Function(
BuildContext context, double shrinkOffset, bool overlapsContent);
class SliverHeaderDelegate extends SliverPersistentHeaderDelegate {
// child 为 header
SliverHeaderDelegate({
required this.maxHeight,
this.minHeight = 0,
required Widget child,
}) : builder = ((a, b, c) => child),
assert(minHeight <= maxHeight && minHeight >= 0);
//最大和最小高度相同
SliverHeaderDelegate.fixedHeight({
required double height,
required Widget child,
}) : builder = ((a, b, c) => child),
maxHeight = height,
minHeight = height;
//需要自定义builder时使用
SliverHeaderDelegate.builder({
required this.maxHeight,
this.minHeight = 0,
required this.builder,
});
final double maxHeight;
final double minHeight;
final SliverHeaderBuilder builder;
@override
Widget build(
BuildContext context,
double shrinkOffset,
bool overlapsContent,
) {
/// >>> update <<<
var child = builder(context, shrinkOffset, overlapsContent);
//测试代码:如果子组件设置了key,则打印日志
if (child.key != null) {
print('${child.key}: shrink: $shrinkOffset,overlaps:$overlapsContent');
}
// 让 header 尽可能充满限制的空间;宽度为 Viewport 宽度,
// 高度随着用户滑动在[minHeight,maxHeight]之间变化。
return SizedBox.expand(
/// >>> update <<<
child: child,
);
}
@override
double get maxExtent => maxHeight;
@override
double get minExtent => minHeight;
@override
bool shouldRebuild(SliverHeaderDelegate old) {
return old.maxExtent != maxExtent || old.minExtent != minExtent;
}
}
// 代码
void main() => Global.init().then((e) => runApp(MyApp()));
Error:
Restarted application in 354ms.
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
#0 MethodChannel.binaryMessenger
#1 MethodChannel._invokeMethod
#2 MethodChannel.invokeMethod
#3 MethodChannel.invokeMapMethod
#4 MethodChannelSharedPreferencesStore.getAll
#5 SharedPreferences._getSharedPreferencesMap
#6 SharedPreferences.getInstance
#7 Global.init
#8 main
#9 _runMainZoned.<anonymous closure>.<anon<…>
runApp未被调用前,无法获取SharedPreferences
平台插件编写章节怎么没有了,比如通过安卓原生获取电量。和原生代码通讯,调用方法以及获取返回值。
原文:
下层组件确定自己的大小,然后告诉商城组件,注意下层组件的大小必须符合父组件的约束。
错字:
商城组件
应为:
上层组件
生态:Flutter 已经有了丰富的生态系统,无论是开发者数量还是第三方组件都已经非常可观。Flutter -->最后多了一个Flutter
国内外有非常基于 Flutter 的成功案例--> 中间少了个字应该
原文:Material 组件库中提供了多种按钮组件如ElevatedButton、FlatButton、OutlineButton等,它们都是直接或间接对RawMaterialButton组件的包装定制,所以他们大多数属性都和RawMaterialButton一样。
其中的FlatButton
应该改成 TextButton
, 然后三个Button是继承ButtonStyleButton
.
你好,你的文章我觉得写得很好,但是我看到了一些描述,或者文字有出入的地方,还是希望给你指出来:
比如 第二章 2.2 Widget 简介 didChangeDependencies什么时候调,这里只介绍了如下:
didChangeDependencies():当State对象的依赖发生变化时会被调用;例如:在之前build() 中包含了一个InheritedWidget,然后在之后的build() 中Inherited widget发生了变化,那么此时Inherited widget的子 widget 的didChangeDependencies()回调都会被调用
但是对象的didChangeDependencies很常见的是在于对象第一次被创建和挂载的时候(包括重创建)对应的didChangeDependencies也会调用,希望在书里面加上这个最常见的调用形式
我的一偏博客也写到了这个话题 https://www.jianshu.com/p/287e3c6210fb
我的邮箱如下 [email protected] 希望能有交流···
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.