在flutter docs中,有一个无状态小部件子类的示例代码,如下所示:
class GreenFrog extends StatelessWidget {
const GreenFrog({ Key key }) : super(key: key);
@override
Widget build(BuildContext context) {
return new Container(color: const Color(0xFF2DBD3A));
}
}
Run Code Online (Sandbox Code Playgroud)
还有这个
class Frog extends StatelessWidget {
const Frog({
Key key,
this.color: const Color(0xFF2DBD3A),
this.child,
}) : super(key: key);
final Color color;
final Widget child;
@override
Widget build(BuildContext context) {
return new Container(color: color, child: child);
}
}
Run Code Online (Sandbox Code Playgroud)
什么是关键,什么时候应该使用这个超级构造函数?好像你有自己的构造函数,你必须有{Key key}为什么?我已经看到了其他没有使用super关键字的例子,所以这就是我的困惑所在.
在 Flutter 中,为了在我们自己的包的 lib 目录中导入库,我们是否应该使用相对导入
import 'foo.dart'
Run Code Online (Sandbox Code Playgroud)
或包导入?
import 'package:my_app/lib/src/foo.dart'
Run Code Online (Sandbox Code Playgroud)
Dart 指南提倡使用相对导入:
在您自己的包的 lib 目录中导入库时,首选相对路径。
- 始终使用包导入。例如:
import 'package:my_app/my_code.dart';
除了简洁之外还有区别吗?为什么包导入会减少相对导入的错误?
我想创建一个在我的Flutter应用程序中显示的超链接.
超链接应嵌入一个Text或类似的文本视图中,如:
The last book bought is <a href='#'>this</a>
任何提示这样做?
我正在尝试为主页设置背景图像.我从屏幕的开始处获取图像位置并填充宽度而不是高度.我在代码中遗漏了什么吗?是否有颤振的图像标准?图像是否根据每部手机的屏幕分辨率进行缩放?
class BaseLayout extends StatelessWidget{
@override
Widget build(BuildContext context){
return new Scaffold(
body: new Container(
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
new Image.asset("assets/images/bulb.jpg")
]
)
)
);
}
}
Run Code Online (Sandbox Code Playgroud) 我仍然在关注 flutter 中的状态管理技术,并且对何时以及为什么使用Provider.of<X>vs. Consumer<X>. 我从文档中了解到(我认为)在这两者之间进行选择时,当我们想要访问数据时,您将使用 Provider.of,但您不需要更改 UI。因此,以下(取自文档)可以访问数据并在新事件上更新 UI:
return HumongousWidget(
// ...
child: AnotherMonstrousWidget(// <- This widget will rebuild on new data events
// ...
child: Consumer<CartModel>(
builder: (context, cart, child) {
return Text('Total price: ${cart.totalPrice}');
},
),
),
);
Run Code Online (Sandbox Code Playgroud)
然而,在这里我们只需要在数据上不希望与UI重建,我们会使用Provider.of<X>与listen参数集false,如下图所示:
Provider.of<CartModel>(context, listen: false).add(item); \\Widget won't rebuild
Run Code Online (Sandbox Code Playgroud)
但是,listen不是必需的,因此以下内容也将运行:
Provider.of<CartModel>(context).add(item); \\listener optional
Run Code Online (Sandbox Code Playgroud)
所以这给我带来了几个问题:
Provider.of<X>和的正确方法吗Consumer<X>?前者不更新用户界面,后者呢?listen未设置为false默认情况下会重建小部件还是不重建?如果listen设置为true呢?我遇到了以下问题:E/flutter (7144): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] 未处理的异常:错误状态:平台不允许不安全的 HTTP:http://myIPv4 :端口/路径。

这是我可以访问的后端:

我已经允许 cors 访问,但即使这对我也没有帮助。我已经尝试使用 http://localhost:port/path 和 http://myIP:port/path 但没有用!
但是如果我尝试通过浏览器直接访问,那么工作。

我已经向 TestFlight 提交了许多应用程序版本,即使是昨天,但今天当我尝试通过 XCODE 将我的应用程序提交给 TestFlight 时,我收到以下错误:
ERROR ITMS-90164: "Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. According to the provisioning profile, the bundle contains a key value that is not allowed: '[ ]' for the key 'com.apple.developer.healthkit.access' in 'Payload/Runner.app/Runner'."
我正在通过 XCODE 构建一个颤振项目。我尝试了以下方法:
但我仍然收到此错误。我的启用与上次上传我的应用程序相比没有改变。请帮忙,谢谢。
更新 1:似乎是在 Apple 端所做的更改导致此错误。Apple 尚未提供官方回应/解释。下面提供了一些解决方法。我为 Health …
我试图将标题文本集中在一个既有前导又有尾随动作的应用栏中.
@override
Widget build(BuildContext context) {
final menuButton = new PopupMenuButton<int>(
onSelected: (int i) {},
itemBuilder: (BuildContext ctx) {},
child: new Icon(
Icons.dashboard,
),
);
return new Scaffold(
appBar: new AppBar(
// Here we take the value from the MyHomePage object that
// was created by the App.build method, and use it to set
// our appbar title.
title: new Text(widget.title, textAlign: TextAlign.center),
leading: new IconButton(
icon: new Icon(Icons.accessibility),
onPressed: () {},
),
actions: [
menuButton,
],
),
body: new …Run Code Online (Sandbox Code Playgroud) 尝试在我的项目中使用 Firestore。我的项目是一个全新的项目,但在我的设备上运行应用程序时出现问题,但没有出现错误: 任务“:app:mergeDexDebug”的执行失败。
我的应用正在使用 AndroidX。我已经添加了我的 google-services.json 文件,按照步骤等操作。
yaml文件:
dependencies:
cloud_firestore: ^0.13.3
Run Code Online (Sandbox Code Playgroud)
android/build.gradle:
com.google.gms:google-services:4.3.3
Run Code Online (Sandbox Code Playgroud)
完整错误:
FAILURE:构建失败,出现异常。
出了什么问题:任务 ':app:mergeDexDebug' 执行失败。执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade com.android.builder.dexing.DexArchiveMergerException 时发生故障:合并 dex 档案时出错:.dex 文件中的方法引用数不能超过 64K。在https://developer.android.com/tools/building/multidex.html了解如何解决此问题