Skip to content

Instantly share code, notes, and snippets.

@hpoul
Last active March 27, 2020 23:23
Show Gist options
  • Save hpoul/aa423731de97aef1160c8b9b812ad1c9 to your computer and use it in GitHub Desktop.
Save hpoul/aa423731de97aef1160c8b9b812ad1c9 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final GlobalKey<NavigatorState> _navigatorKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
SizedBox(
width: 200,
child: Scaffold(
body: Container(
alignment: Alignment.center,
padding: EdgeInsets.all(16),
child: TextField(
decoration: InputDecoration(hintText: 'Type here'),
onChanged: (newValue) {
print('done. newValue: $newValue');
_navigatorKey.currentState.pushAndRemoveUntil(
MaterialPageRoute(builder: (_) => PageWithTextField()),
(route) => false);
},
),
),
),
),
Expanded(
child: Navigator(
key: _navigatorKey,
onGenerateRoute: (settings) {
assert(settings.name == Navigator.defaultRouteName);
return MaterialPageRoute<void>(
settings: settings,
builder: (context) => EmptyPage(),
);
},
),
),
],
);
}
}
class EmptyPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Lorem'),
),
body: const Center(
child: Text('Nothing to see here.'),
));
}
}
class PageWithTextField extends StatefulWidget {
@override
_PageWithTextFieldState createState() => _PageWithTextFieldState();
}
class _PageWithTextFieldState extends State<PageWithTextField> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Lorem'),
),
body: const Center(
child: Text('Detail Page'),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment