Created
May 31, 2019 06:27
-
-
Save markmooibroek/3459f73bbd89deefeb488060f5bfd87e to your computer and use it in GitHub Desktop.
Navigator bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text("Navigators")), | |
body: Column( | |
mainAxisSize: MainAxisSize.max, | |
children: [ | |
Expanded(child: TopPanel()), | |
Expanded(child: BottomPanel()), | |
], | |
), | |
); | |
} | |
} | |
class TopPanel extends StatefulWidget { | |
@override | |
_TopPanelState createState() => _TopPanelState(); | |
} | |
class _TopPanelState extends State<TopPanel> { | |
final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>(); | |
TextEditingController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = TextEditingController(); | |
} | |
@override | |
void dispose() { | |
controller?.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Navigator( | |
key: _navigatorKey, | |
initialRoute: "/", | |
onGenerateRoute: (settings) { | |
return MaterialPageRoute(builder: (context) { | |
return Container( | |
color: Colors.green, | |
child: Center( | |
child: TextFormField( | |
controller: controller, | |
decoration: InputDecoration(hintText: "Input"), | |
), | |
), | |
); | |
}); | |
}); | |
} | |
} | |
class BottomPanel extends StatefulWidget { | |
BottomPanel({Key key}) : super(key: key); | |
_BottomPanelState createState() => _BottomPanelState(); | |
} | |
class _BottomPanelState extends State<BottomPanel> { | |
TextEditingController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = TextEditingController(); | |
} | |
@override | |
void dispose() { | |
controller?.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.red, | |
child: Center( | |
child: TextFormField( | |
controller: controller, | |
decoration: InputDecoration(hintText: "2nd input"), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment