gpt4 book ai didi

flutter - Dart/Flutter : Navigate (with Navigator) between Pages without context (so no Navigator. 推送?)

转载 作者:行者123 更新时间:2023-12-03 02:54:46 31 4
gpt4 key购买 nike

在我的应用程序中,我有 6 个不同的页面。
有 1 个页面称为“收藏夹页面”,其中列出了用户选择的收藏夹。它们由一列显示,该列使用来自另一个类的列表。列表代码如下:

  List<Widget> favoriteContainerLists() {
DatabaseProvider.db.queryDb();
List<Widget> localList = [];
if (DatabaseProvider.publicFavoriteList == null ||
DatabaseProvider.publicFavoriteList.isEmpty) {
localList.add(
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Hier erscheinen deine Favoriten!",
style: TextStyle(
fontFamily: "Hind",
fontSize: 22,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Makiere Bilder auf der Informationsseite mit ",
style: TextStyle(
color: Colors.indigo,
fontFamily: "Hind",
fontSize: 15,
),
),
Icon(
Icons.star_border,
color: Colors.orange,
),
],
),
Text(
" um sie hinzuzufügen!",
style: TextStyle(
color: Colors.indigo,
fontFamily: "Hind",
fontSize: 15,
),
),
],
),
);
} else {
localList.add(Padding(
padding: const EdgeInsets.only(bottom: 15.0),
child: Text(
"Deine Favoriten:",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 30,
color: Colors.indigoAccent,
fontFamily: "Hind",
),
),
));
for (var i = 0; i < DatabaseProvider.publicFavoriteList.length; i++) {
DatabaseProvider.db.queryDb();
int currentIdInt = DatabaseProvider.publicFavoriteList[i];
localList.add(
Padding(
padding: const EdgeInsets.only(bottom: 15),
child: MaterialButton(
onPressed: ***null***,
padding: const EdgeInsets.only(bottom: 0),
child: Container(
width: double.infinity,
height: 120,
decoration: BoxDecoration(
color: buttonColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
bottomLeft: Radius.circular(8),
bottomRight: Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 8, 10, 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
width: 70,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
bottomLeft: Radius.circular(8),
bottomRight: Radius.circular(8)),
),
child: Image.asset(
AppBrain().contentList[currentIdInt].imageAdress),
),
),
VerticalDivider(
thickness: 2,
indent: 15,
endIndent: 15,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
AppBrain().contentList[currentIdInt].artName,
style: TextStyle(
fontFamily: "Hind",
fontSize: 23,
color: Colors.blueGrey),
),
Expanded(
child: Container(
child: RichText(
maxLines: 2,
softWrap: true,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.left,
text: TextSpan(
style: TextStyle(
fontSize: 14,
color: Colors.black,
fontFamily: "Hind"),
text:
(contentList[currentIdInt].description),
),
),
),
)
],
),
),
],
),
),
),
),
),
);
}
}
return localList;
}
显示它的页面代码:
  Widget build(BuildContext context) {
DatabaseProvider.db.queryDb();
return SafeArea(
child: Scaffold(
backgroundColor: Colors.white,
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home), title: Text("Startseite")),
BottomNavigationBarItem(
icon: Icon(Icons.star), title: Text("Favoriten")),
BottomNavigationBarItem(
icon: Icon(Icons.casino), title: Text("Quiz")),
BottomNavigationBarItem(
icon: Icon(Icons.map), title: Text("Karte")),
],
type: BottomNavigationBarType.fixed,
unselectedItemColor: Colors.grey,
showUnselectedLabels: true,
currentIndex: _selectedIndex,
selectedItemColor: Colors.blue,
onTap: _onItemTapped,
),
body: SingleChildScrollView(
child: WillPopScope(
onWillPop: _backButtonPressed,
child: Padding(
padding: const EdgeInsets.only(left: 15, right: 15, top: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: AppBrain().favoriteContainerLists(),
),
),
),
),
),
);
}
它们位于 2 个不同的类中。包含列表的类没有 BuildContext,也应该有非。理想情况下,它说 onTap: null,目前我希望它是
Navigator.of(context).push(
toInformationPage(),
);
但我知道我不能使用任何需要上下文的东西。有任何想法吗?

最佳答案

您将 GlobalKey 用于导航器。已经有很多文章描述了如何去做,这里是an example

关于flutter - Dart/Flutter : Navigate (with Navigator) between Pages without context (so no Navigator. 推送?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63962860/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com