fork download
  1.  
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:provider/provider.dart'; // .yaml file provider: ^3.1.0+1
  5.  
  6. void main() {
  7. runApp(MaterialApp(
  8. title: 'Navigation Basics',
  9. home: FirstRoute(),
  10. ));
  11. }
  12.  
  13.  
  14. class FirstRoute extends StatelessWidget {
  15. @override
  16. Widget build(BuildContext context) {
  17. return ChangeNotifierProvider(
  18. builder: (context) => Data(),
  19. child: Scaffold(
  20. appBar: AppBar(
  21. title: Text('First Route'),
  22. ),
  23. body: Column(
  24. children: <Widget>[
  25. Container(
  26. width: 256,
  27. margin: const EdgeInsets.only(bottom: 8),
  28. child: TextField(
  29. decoration: InputDecoration(
  30. hintText: 'Enter user name', labelText: 'User Name'),
  31. onChanged: (String newUserName){
  32. Provider.of<Data>(context).changePassword(newUserName);
  33. print(newUserName);
  34. },
  35. ),
  36. ),
  37. Container(
  38. width: 256,
  39. margin: const EdgeInsets.only(bottom: 8),
  40. child: TextField(
  41. obscureText: true,
  42. decoration: InputDecoration(
  43. hintText: 'Enter password', labelText: 'Password'),
  44. onChanged: (String newPassword){
  45. Provider.of<Data>(context).changePassword(newPassword);
  46. print(newPassword);
  47. },
  48. ),
  49. ),
  50. Center(
  51. child: RaisedButton(
  52. child: Text('Open route'),
  53. onPressed: () {
  54. Navigator.push(
  55. context,
  56. MaterialPageRoute(builder: (context) => SecondRoute()),
  57. );
  58. },
  59. ),
  60. ),
  61. ],
  62. ),
  63. ),
  64. );
  65. }
  66. }
  67.  
  68. class SecondRoute extends StatelessWidget {
  69. @override
  70. Widget build(BuildContext context) {
  71. return Scaffold(
  72. appBar: AppBar(
  73. title: Text("Second Route"),
  74. ),
  75. body: Column(
  76. children: <Widget>[
  77. Center(
  78. child: RaisedButton(
  79. onPressed: () {
  80. Navigator.pop(context);
  81. },
  82. child: Text('Go back!'),
  83. ),
  84. ),
  85. Text(
  86. Provider.of<Data>(context).userName,
  87. // Provider.of<String>(context),
  88. style: TextStyle(
  89. color: Colors.blue,
  90. fontSize: 20.0
  91. ),
  92. ),
  93. Text(
  94. Provider.of<Data>(context).password,
  95. // Provider.of<String>(context),
  96. style: TextStyle(
  97. color: Colors.green,
  98. fontSize: 20.0
  99. ),
  100. ),
  101. ],
  102. ),
  103. );
  104. }
  105. }
Runtime error #stdin #stdout #stderr 1.02s 126372KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: Could not resolve the package 'flutter' in 'package:flutter/material.dart'.
Error: Could not resolve the package 'provider' in 'package:provider/provider.dart'.
prog.dart:3:8: Error: Not found: 'package:flutter/material.dart'
import 'package:flutter/material.dart';
       ^
prog.dart:4:8: Error: Not found: 'package:provider/provider.dart'
import 'package:provider/provider.dart'; // .yaml file provider: ^3.1.0+1
       ^
prog.dart:16:16: Error: Type 'BuildContext' not found.
  Widget build(BuildContext context) {
               ^^^^^^^^^^^^
prog.dart:16:3: Error: Type 'Widget' not found.
  Widget build(BuildContext context) {
  ^^^^^^
prog.dart:14:26: Error: Type 'StatelessWidget' not found.
class FirstRoute extends StatelessWidget {
                         ^^^^^^^^^^^^^^^
prog.dart:70:16: Error: Type 'BuildContext' not found.
  Widget build(BuildContext context) {
               ^^^^^^^^^^^^
prog.dart:70:3: Error: Type 'Widget' not found.
  Widget build(BuildContext context) {
  ^^^^^^
prog.dart:68:27: Error: Type 'StatelessWidget' not found.
class SecondRoute extends StatelessWidget {
                          ^^^^^^^^^^^^^^^