有人能帮帮我吗为什么Navigator.push()
在我的ElevatedButton()
上不起作用?当我按下按钮时,什么也没发生:
import 'package:flutter/material.dart';
import 'package:metroguia/constants/colors.dart';
import '../../selecao__linha/selecao_linhas.dart';
class HomeCard extends StatelessWidget {
const HomeCard({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
width: 281,
height: 111,
decoration: BoxDecoration(
color: orangeDetails.withOpacity(0.8),
borderRadius: BorderRadius.circular(9),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 3,
blurRadius: 4,
offset: const Offset(0, 2) // muda a posição da sombra
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image.asset(
"assets/images/metro.png",
width: 100,
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Align(
alignment: Alignment.center,
child: Text(
"Acompanhe a rotas das linhas \n e estações do metrô \n de Recife",
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 65
),
//Button
child: SizedBox(
height: 18,
child: ElevatedButton(
onPressed: (){
Navigator.push(
context,
MaterialPageRoute(builder:
((context) => const selecaoLinha())
)
);
},
style: ButtonStyle(
elevation: MaterialStateProperty.all(0),
foregroundColor: MaterialStateProperty.all(Colors.black),
backgroundColor:MaterialStateProperty.all(blueDetails),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(3),
)
)
),
child: const Text(
"VER LINHAS",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600
),
),
),
),
),
],
),
],
),
);
}
}
我想将屏幕导航到下面的屏幕:
import 'package:flutter/material.dart';
import 'package:metroguia/pages/linha__selecionada/linha__centro_jaboatao/linha__jaboatao.dart';
class selecaoLinha extends StatefulWidget {
const selecaoLinha({Key? key}) : super(key: key);
@override
State<selecaoLinha> createState() => _selecaoLinhaState();
}
class _selecaoLinhaState extends State<selecaoLinha> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Jaboatao()
);
}
}
我尝试使用Inkwell()
与onTap()
,但不工作,什么也没有发生。我不知道发生了什么,我按下按钮,继续到homePage()
。
1条答案
按热度按时间uplii1fm1#
我个人写的
.push()
方法有点不同,它工作得很好,试试这个:用你需要的东西改变
const Page()
,你应该没事,如果不是,请提供一些堆栈跟踪或更新你的问题更多的细节,快乐编码!