[英]Flutter: Cupertino ListTile ? (or How To Create iOS-Like-Settings Menu)
Do we have an easy way of doing that kind of menu below using CupertinoApp
only?我们是否有一种仅使用CupertinoApp
来执行下面那种菜单的简单方法?
Ok, so we can use a Scaffold
inside a CupertinoPageScaffold
like that and still use the material ListTile
which look the same as Cupertino ones.好的,所以我们可以像这样在CupertinoPageScaffold
使用Scaffold
,并且仍然使用与 Cupertino 相同的材质ListTile
。
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('My List'),
),
child: SafeArea(
child: Scaffold(
body: _listView(context),
),
),
);
}
You can try this at pub.dev:你可以在 pub.dev 上试试这个:
cupertino_list_tile: ^0.2.0
https://pub.dev/packages/cupertino_list_tile https://pub.dev/packages/cupertino_list_tile
I was able to achieve results very close to the iOS list by using CupertinoButton instead of ListTile, it's a really flexible component.通过使用 CupertinoButton 而不是 ListTile,我能够获得非常接近 iOS 列表的结果,这是一个非常灵活的组件。 It also apparently has no ripple effect.它显然也没有连锁反应。
The only drawback to this approach is that the button uses pressedOpacity, but reducing the default value from 0.4 to 0.65 or something like that will work just fine.这种方法的唯一缺点是按钮使用了pressedOpacity,但是将默认值从0.4减少到0.65或类似的东西就可以了。
CupertinoButton(
pressedOpacity: 0.65,
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(0),
),
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
alignment: Alignment.centerLeft,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
const Padding(
padding: EdgeInsets.only(right: 12),
child: SizedBox(
height: 28,
width: 28,
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.teal,
borderRadius: BorderRadius.all(
Radius.circular(4),
),
),
child: Icon(
Icons.ac_unit_sharp,
color: Colors.white,
),
),
),
),
Text(
'Snowflake item',
style: TextStyle(color: Colors.black),
),
],
),
const Icon(
Icons.chevron_right,
color: Colors.grey,
),
],
),
onPressed: () {},
)
Flutter 3.7 added two new widgets: CupertinoListSection
and CupertinoListTile
for showing a scrollable list of widgets in the iOS style. Flutter 3.7添加了两个新小部件: CupertinoListSection
和CupertinoListTile
,用于显示 iOS 样式的可滚动小部件列表。
PR: https://github.com/flutter/flutter/pull/78732公众号:https://github.com/flutter/flutter/pull/78732
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.