我想使用Push Name从第1页到第2页,并使用Disdisable Widget关闭第2页.
按下按钮时,关闭时会出现黑屏.
当我拉下关闭第2页时,我想看到第1页
我举了this个例子
class FirstScreen extends StatelessWidget {
const FirstScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('First Screen'),
),
body: Center(
child: ElevatedButton(
// Within the `FirstScreen` widget
onPressed: () {
// Navigate to the second screen using a named route.
Navigator.pushNamed(context, '/second');
},
child: const Text('Launch screen'),
),
),
);
}
}
class SecondScreen extends StatelessWidget {
const SecondScreen({super.key});
@override
Widget build(BuildContext context) {
return Dismissible(
key: UniqueKey(),
movementDuration: const Duration(milliseconds: 0),
resizeDuration: const Duration(milliseconds: 1),
onDismissed: (d) => Navigator.of(context).pop(),
direction: DismissDirection.down,
child: Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
body: Center(
child: ElevatedButton(
// Within the SecondScreen widget
onPressed: () {
// Navigate back to the first screen by popping the current route
// off the stack.
Navigator.pop(context);
},
child: const Text('Go back!'),
),
),
),
);
}
}
如果我用这个,它就能用了!但我不想用它
Navigator.of(context).push(
PageRouteBuilder(
opaque: false,
pageBuilder: (context, animation, secondaryAnimation) => const SecondScreen(),
));
void main() {
runApp(
MaterialApp(
title: 'Named Routes Demo',
initialRoute: '/',
routes: {
'/': (context) => const FirstScreen(),
'/second': (context) => const SecondScreen(), }, ),
);
}