I want to change a window with a simple swipe to the left, I have to 2 windows and when user swipes to the right side, I want to change my route.
I'm working with Named Routes.
void main() => runApp(new HeatMapApp());
class HeatMapApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'HeatMap',
initialRoute: '/',
routes: {
'/': (context) => new Main(),
'/home': (context) => new Home()
},
theme: new ThemeData(
primaryColor: Colors.black
)
);
}
}
This is my code in my App, the Main file doesn't have too much data now, I want to know the swipe event to redirect to 'home' path.
Main.dart
class Main extends StatelessWidget {
final bool _isLoggedIn = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _isLoggedIn ? AppBar (
title: Text('Logged In')
) : null,
body: Center(
child: Text('Hello World!')
)
);
}
}
I think Dismissible
Widget fits perfect on your requirement
class Main extends StatelessWidget {
final bool _isLoggedIn = true;
_nextPage(BuildContext context) async {
Navigator.of(context).pushReplacementNamed("/home");
}
@override
Widget build(BuildContext context) {
return Dismissible(
key: new ValueKey("dismiss_key"),
direction: DismissDirection.endToStart,
child: Scaffold(
appBar: _isLoggedIn ? AppBar(title: Text('Logged In')) : null,
body: Center(child: Text('Hello World!'))),
onDismissed: (direction) {
if (direction == DismissDirection.endToStart) {
_nextPage(context);
}
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With