i am trying to call Navigator.pop(context);
from Dismissible
like following
@override
Widget build(BuildContext context) {
return Dismissible(
key: const Key('some key here'),
direction: DismissDirection.down,
onDismissed: (l) {
Navigator.pop(context);
},
child: const Scaffold(
backgroundColor: Colors.yellowAccent,
),
);
}
}
it is work fine but the problem is once i swipe i see black screen !
how could i make it transparent so i can see the previous page instead of black screen ..
if it is not possible with Dismissible
please suggest to me any other way to make it done
import 'package:flutter/material.dart';
class myFirstPag extends StatefulWidget {
const myFirstPag({Key? key}) : super(key: key);
@override
myFirstPagState createState() => myFirstPagState();
}
class myFirstPagState extends State<myFirstPag> {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: (){
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
return mySecPag();
}
)
);
},
child: const Scaffold(
backgroundColor: Colors.red,
body: Center(child: Text('my First Page')
),
),
);
}
}
class mySecPag extends StatefulWidget {
const mySecPag({Key? key}) : super(key: key);
@override
mySecPagState createState() => mySecPagState();
}
class mySecPagState extends State<mySecPag> {
@override
Widget build(BuildContext context) {
return Dismissible(
key: const Key('some key here'),
direction: DismissDirection.down,
onDismissed: (l) {
Navigator.pop(context);
},
child: const Scaffold(
backgroundColor: Colors.yellowAccent,
body: Center(child: Text('my sec page'),),
),
);
}
}
4
Answers
i found solution finally ..
Try This Code:
I don’t think you will able to achive it by
Dismissible
widget:I have modified your code slightly to this:
I have added
background
property inDismisible
Widget, now whenever you swipe you can see that color will be shown.But the style you want to achieve, you can do it with
CupertinoRoutes
.Example of your code using
CupertinoRoutes
routes:Here’s the full tutorial for it: Link
You can try this code:
First screen
Second screen: