flutter - flutter-web:打开网页细节部分的最佳方式是什么
问题描述
我可以把这些东西写成小部件的页面。但我希望有更好的方法,因为我认为这是网络的正常情况。
重现步骤
IconButton()
在小部件中包含内容列表。- 使用 运行后
flutter run -d chrome
,它将以 chrome 显示。 - 我尝试单击列表中的每个按钮以打开详细信息。
预期 2 个可能的结果:
- 在列表部件区域中打开详细部件。
- 或使用新标签打开详细信息,但最好共享菜单和顶部。我认为这与https://github.com/flutter/flutter/issues/33126的情况不同。
我可以实现结合菜单和顶部打开详细信息页面,但我不喜欢这种方式用于网络。
解决方案
您可以使用ExpansionTile
小部件中的ListView
小部件来获取预期的Result-1,如下所示。
此dartpad中提供了一个实时示例。
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyExpansionTile(),
),
),
);
}
}
class MyExpansionTile extends StatelessWidget {
// defining the title and descriptions.
final List<String> titles = ['title-1', 'title-2', 'title-3'];
final List<String> descriptions = [
'Description for title-1',
'Description for title-2',
'Detailed Description for title-3'
];
@override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (context, index) {
// handle index out of range.
if(index >= titles.length)
return null;
// build and expansion tile for each title and description.
return ExpansionTile(
// comment following to show an arrow in the end of each expansion tile as per material design.
trailing: Container(width: 0, height:0),
leading: Icon(Icons.open_in_browser),
title: Text(titles[index]),
children: <Widget>[
Text(descriptions[index]),
],
);
},
);
}
}
这将呈现扩展图块,如下所示。展开图块是可点击的,点击时展开和折叠。
推荐阅读
- typescript - 为什么类不能被视为构造函数?
- python - 框架和keras模型
- swift - 如何在 Swift 中的 png 图像后面添加一个 Circle()
- android - Android xml 布局显示为灰色
- c# - Intellocked.Exchange 而不是 ReaderWriterLockSlim
- java - 如何将数据传递给 Platform.runLater
- discord - discord.py 删除所有玩家的所有角色
- notifications - Swift UI 2.0:如何设置此通知?
- sql - Oracle sql中特殊字符<和>的转义
- java - 计算给定列表的 n 个幂集