gpt4 book ai didi

flutter - 我想导航到主屏幕而不使用抽屉

转载 作者:行者123 更新时间:2023-12-03 04:45:00 25 4
gpt4 key购买 nike

在传递下面的字符串属性时,导航是否可以直接进入主屏幕而不是pop(抽屉)?cityName属性无法使用pushNamed传递。
请告诉我是否有办法
我可以在onpressed中使用navigator.pop以外的其他内容吗?

import 'package:flutter/material.dart';
import '../const.dart';

class CityScreen extends StatelessWidget {
static const String routeName = '/cityScreen';

@override
Widget build(BuildContext context) {
final _mycontroller = TextEditingController();
String cityName;

return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/city.jpg'),
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.6), BlendMode.dstATop),
fit: BoxFit.cover,
)),
constraints: BoxConstraints.expand(),
child: SafeArea(
child: Column(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Icon(Icons.arrow_back_ios, size: 30),
),
),
Container(
padding: EdgeInsets.all(25),
child: TextField(
decoration: InputDecoration(
icon: Icon(Icons.search),
filled: true,
hintText: 'Enter City Name'),
controller: _mycontroller,
autofocus: true,
onChanged: (value) {
cityName = value;
},
),
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.white)),
onPressed: () {
Navigator.pop(context, cityName);
},
child: Text(
'Click here',
style: kbuttonStyle,
),
)
],
),
),
),
);
}
}

最佳答案

您可以像下面这样在pushReplacementNamed / pushNamed中传递参数:

 Navigator.pushReplacementNamed(
context,
"dashboard_route",
arguments: "cityName",
);
然后在仪表板Widget构建函数中,执行以下操作以获取cityName:
final String cityName = ModalRoute.of(context).settings.arguments;

关于flutter - 我想导航到主屏幕而不使用抽屉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62495218/

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