Skip to content

Instantly share code, notes, and snippets.

@SergioEric
Created October 4, 2020 02:31
Show Gist options
  • Save SergioEric/f163d6d09ee8d6e564691a48100b12ed to your computer and use it in GitHub Desktop.
Save SergioEric/f163d6d09ee8d6e564691a48100b12ed to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
));
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Color(0xff131313),
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Navigator(
initialRoute: '/',
onPopPage: (route, result) {
print("route $route");
print("result" + result);
return false;
},
onGenerateRoute: (RouteSettings settings) {
print(settings);
print(settings.name);
switch(settings.name){
case '/home':
return MaterialPageRoute(
builder: (_)=>HomePage(),
settings: settings
);
case '/other':
return MaterialPageRoute(
builder: (_)=>OtherPage(),
settings: settings
);
}
return MaterialPageRoute(
builder: (_)=>HomePage(),
settings: settings
);
},
),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Home Page"),
),
body: Column(
children: [
TextButton(
onPressed: ()=> Navigator.pushNamed(context, "/other"),
child: Text("ir a otra pagina")
)
],
),
);
}
}
class OtherPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Otra Page"),
),
body: Column(
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: ()=>Navigator.pop(context),
),
TextButton(
onPressed: ()=> Navigator.push(context,
MaterialPageRoute(builder: (_)=>Scaffold(
appBar: AppBar(
title: Text("3er Page"),
)
))
),
child: Text("3ra pagina")
)
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment