-
TextFormField:我无法在 Cupertino 设计中找到与表单一起使用的 TextFormField...
-
Validator:如何验证CupertinoTextField,因为没有验证器方法
在 Cupertino 中没有带有验证和表单方法的 TextField。在 iOS 开发中,您将编写自己的表单验证代码并相应地调用它们。在 Flutter 中也不例外。
一种典型的方法是创建一个内部_FormData 类来为每个CupertinoTextField 存储TextEditingController,然后在CupertinoButton 的onPressed 回调中验证它们。
- App Drawer:现在我有 App Drawer。当我转向适用于 IOS 和 Android 的 Cuprtino UI 设计时,我应该放弃 App Drawer 吗?
同样,Drawer 小部件仅存在于 Material design 中。您可能在市场上的各种 iOS 应用程序中看到的所有抽屉都是由第三方提供商定制的 UIViews。 Apple Human Interface Guidelines明确表示:
避免使用抽屉。现代应用中很少使用抽屉,不鼓励使用。面板、弹出框、侧边栏和拆分视图是显示补充窗口内容的首选。
您可能需要考虑使用CupertinoPageScaffold 或CupertinoTabScaffold,具体取决于您的设计要求。
- 如何给出 CupertinoButton 的宽度?
您可以用Container、SizedBox 或FractionallySizedBox 包裹您的CupertinoButton。
Container(
width: 300 // or whatever width you want,
child: CupertinoButton(
child: Text('Submit'),
color: Theme.of(context).primaryColor,
onPressed: () {
// Write your callback here
},
),
)
或
SizedBox(
width: 300 // or whatever you want,
child: CupertinoButton(
child: Text('Submit'),
color: Theme.of(context).primaryColor,
onPressed: () {
// Write your callback here
},
),
)
或
FractionallySizedBox(
widthFactor: 0.5 // or whatever you want,
child: CupertinoButton(
child: Text('Submit'),
color: Theme.of(context).primaryColor,
onPressed: () {
// Write your callback here
},
),
)
一般来说,Container 应该可以解决问题。如果您将CupertinoButton 包装在Flex 小部件中(例如ListView、Column),您可能需要使用SizedBox 或FractionallySizedBox。可以参考SizedBox和FractionallySizedBox的API文档
- 当我尝试迁移到 Cuprtio 时,ListTitle 引发异常。例外情况是“找不到 Material 祖先的特定小部件是:ListTitle”
正如错误日志所说:
在材料设计中,大多数小部件在概念上都“打印”在一张材料上。在 Flutter 的材质库中,该材质由 Material Widget 表示。例如,渲染墨水飞溅的是 Material 小部件。正因为如此,许多材质库小部件都要求它们上方的树中有一个 Material 小部件。
要引入 Material 小部件,您可以直接包含一个,或使用包含 Material 本身的小部件,例如 Card、Dialog、Drawer ,或Scaffold。
我猜你正在尝试在 CupertinoPageScaffold 或 CupertinoTabView 中使用 ListTile(这是一个 Material 小部件),这显然是 Cupertino 小部件。我就是这样解决的:
Material(
type: MaterialType.transparency,
child: ListTile(
...
)
)