英文:
Flutter: How to pass tapped text between pages?
问题
我已经创建了两个页面
显示来自Firestore的数据
在一个页面上,它以可点击的文本形式显示集合列表
(这是一个子集合)
需要在第二个页面中显示相关子集合
请帮忙
我已经硬编码了子集合并显示了,但需要使其动态,请帮助。
英文:
I have created two pages
displays data from firestore
in one page it shows list of collections as text which is tapabble
(it is a subcollection)
need to display relevent subcollections in second page
please help
I have hard coded subcollection and displayed , but need to be dynamic please help
答案1
得分: 1
以下是代码的翻译部分:
请参考下面的示例代码以传递参数
```dart
class FirstScreen extends StatefulWidget {
const FirstScreen({Key key}) : super(key: key);
@override
_FirstScreenState createState() => _FirstScreenState();
}
class _FirstScreenState extends State<FirstScreen> {
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondScreen(
dataList: ["Data"],
),
),
);
},
child: Text(
"Second Screen",
),
),
),
);
}
}
class SecondScreen extends StatefulWidget {
final List dataList;
const SecondScreen({Key key, this.dataList}) : super(key: key);
@override
_SecondScreenState createState() => _SecondScreenState();
}
class _SecondScreenState extends State<SecondScreen> {
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: Text(
widget.dataList[0].toString(),
),
),
);
}
}
<details>
<summary>英文:</summary>
Please refer to below example code for passing arguments
class FirstScreen extends StatefulWidget {
const FirstScreen({Key key}) : super(key: key);
@override
_FirstScreenState createState() => _FirstScreenState();
}
class _FirstScreenState extends State<FirstScreen> {
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondScreen(
dataList: ["Data"],
),
),
);
},
child: Text(
"Second Screen",
),
),
),
);
}
}
class SecondScreen extends StatefulWidget {
final List dataList;
const SecondScreen({Key key, this.dataList}) : super(key: key);
@override
_SecondScreenState createState() => _SecondScreenState();
}
class _SecondScreenState extends State<SecondScreen> {
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: Text(
widget.dataList[0].toString(),
),
),
);
}
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论