Monday, May 14, 2018

Motiv. Quote App: Go to another screen/page (Routes and Navigation) in Flutter



Using Named route:

import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'Navigation and routes',
home: MyApp(),
routes: <String, WidgetBuilder>{
'/SecondPage': (BuildContext context) => new SecondPage(),
},
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () => Navigator.pushNamed(context, '/SecondPage'),
child: Text('Second Page'),
),
],
),
);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Second Page'),),
body: Center(
child: RaisedButton(
onPressed: () => Navigator.pop(context),
child: Text('Go Back'),
),
),
);
}
}

No comments:

Post a Comment