gpt4 book ai didi

flutter 后退按钮按下

转载 作者:IT王子 更新时间:2023-10-29 07:22:26 26 4
gpt4 key购买 nike

WillPopScope 不会在我的 android 后退按钮设备上使用react,但它会在 flutter 箭头返回上使用react。有人知道如何解决这个问题吗?

class DetailScreen extends StatelessWidget {
final Property property;
const DetailScreen(this.property);

return WillPopScope(
onWillPop: () {
_goToProjects(context);
},
child: ScopedModelDescendant<PropertyScopedModel>(
builder: (context, child, model) => Scaffold(

backgroundColor: Color(0xff253138),
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: () {_goToProjects(context);} ),
pinned: true,
floating: false,
title: Text('Project titel')),
SliverList(
delegate: SliverChildListDelegate([
Container(
color: Color(0xff2f3e47),
padding: const EdgeInsets.all(16),
margin: const EdgeInsets.symmetric(vertical: 2.0),

child: Column(

mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[

Expanded(
child: Text(
"INTERN",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold),
),
),
Chip(
backgroundColor: Colors.green.shade800,
labelStyle: TextStyle(color: Colors.white),
label: Text('In planning'),
)
],
),
SizedBox(
height: 10,
),
Text(
"Project titel",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
),
Text(
property.summary,
style: Theme.of(context).textTheme.body2,
),
],
),
),


Container(
color: Color(0xff2f3e47),
margin: const EdgeInsets.symmetric(vertical: 2.0),
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Align(
alignment: Alignment.center,
child: Container(
child: Text("",
style: TextStyle(
color: Colors.blue, fontSize: 16))),
),
ListTile(
leading: Icon(Icons.pin_drop, color: Colors.white),
title: Text("",
style: TextStyle(fontSize: 14)),
subtitle: Text("",
style: TextStyle(fontSize: 14)),
onTap: () {
_launchMaps();
},
),
ListTile(
leading: Icon(Icons.local_phone, color: Colors.white),
title: Text('',
style:
TextStyle(color: Colors.blue, fontSize: 14)),
onTap: () => launch(""),
),
ListTile(
leading: Icon(Icons.mail, color: Colors.white),
title: Text('',
style: TextStyle(fontSize: 14)),
onTap: () {
_launchMail();
},
),
ListTile(
leading: Icon(Icons.web, color: Colors.white),
title: Text(
'',
style: TextStyle(color: Colors.blue, fontSize: 14),
),
onTap: () {
_launchURL();
},
),
],
),
),
Container(
margin: const EdgeInsets.symmetric(vertical: 2.0),
),
Container(
color: Color(0xff2f3e47),
margin: const EdgeInsets.symmetric(vertical: 0.0),
padding: const EdgeInsets.all(12),

child: Row(
children: <Widget>[
Text(
"Taken",
style: Theme.of(context)
.textTheme
.title
.copyWith(fontSize: 20.0),
),
],
),
),



InkWell(
onTap: () {
print('test');
},
child: Container(

color: Color(0xff2f3e47),
child: Row(
children: <Widget>[
Expanded(
child: Container(

padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Divider(height: 3, color: Color(0xff253138),),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ),
Text('12-02-2019'),
],
),

SizedBox(
height: 10,
),

Row(
children: <Widget>[
Expanded(
child: Text(
property.summary,
style: Theme.of(context)
.textTheme
.body2,
),
),
Chip(
backgroundColor:
Colors.green.shade800,
label: Text('In planning'),
)
],
),
Divider(height: 3, color: Colors.red,),
],
),
),
),
],
),
),
),
Container(
margin: const EdgeInsets.symmetric(vertical: 2.0),
),
Container(
color: Color(0xff2f3e47),
margin: const EdgeInsets.symmetric(vertical: 2.0),
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
"Lister",
style: Theme.of(context)
.textTheme
.title
.copyWith(fontSize: 20.0),
),
),
ListTile(
leading: Icon(Icons.account_circle),
title:
Text("${property?.listerName ?? "unavailable"}"),
subtitle: Text(
"${property?.datasourceName ?? "source unavailable"}"),
),
],
),
),
]))
],
),
floatingActionButton: AnimatedFloatingActionButton(
//Fab list
fabButtons: <Widget>[float1(), float2(), float3()],
colorStartAnimation: Color(0xff0f70b7),
colorEndAnimation: Colors.red,
animatedIconData: AnimatedIcons.menu_close //To principal button
),
),
),
);
}
}

他应该对此使用react:

void _goToProjects(context) {
print('test');
Navigator.push(context, MaterialPageRoute(builder: (context) {
return GetProjects();
}));

}

尝试了很多不同的东西,但没有任何效果。我希望有人知道如何解决这个问题并且知道我做错了什么。

提前致谢

最佳答案

WillPopScope 是一个 StatefulWidget 小部件。因此,将您的 DetailScreen 类转换为 StatefulWidget 类。

无论你在哪里将 property.summary 更改为 widget.property.summary 并尝试在您的项目中更改此代码:

        class DetailScreen extends StatefulWidget {
final Property property;
DetailScreen({Key key, this.property}) : super(key: key);
@override
DetailScreenState createState() {
return DetailScreenState();
}
}

class DetailScreenState extends State<DetailScreen> {
Future<bool> _goToProjects() {
print('test');
return Navigator.push(
context, MaterialPageRoute(builder: (context) => GetProjects()));
}


return WillPopScope(
onWillPop: _goToProjects,
child: ScopedModelDescendant<PropertyScopedModel>(
...
Text(
"Project titel",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
),
Text(
widget.property.summary,
style: Theme.of(context).textTheme.body2,
),
... code
Row(
children: <Widget>[
Expanded(
child: Text(
widget.property.summary,
style: Theme.of(context)
.textTheme
.body2,
),
),
Chip(
backgroundColor:
Colors.green.shade800,
label: Text('In planning'),
)
],
),
..rest of your code
),
);
}

关于 flutter 后退按钮按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55002396/

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