解決したい課題
下記エラーを解消したい。
エラー
lib/main.dart:9:7: Error: The non-abstract class 'MyApp' is missing implementations for these members: - StatefulWidget.createState Try to either - provide an implementation, - inherit an implementation from a superclass or mixin, - mark the class as abstract, or - provide a 'noSuchMethod' implementation. class MyApp extends StatefulWidget { ^^^^^ /C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart:925:9: Context: 'StatefulWidget.createState' is defined here. State createState(); ^^^^^^^^^^^ lib/main.dart:61:7: Error: The non-abstract class 'NextPage' is missing implementations for these members: - StatefulWidget.createState Try to either - provide an implementation, - inherit an implementation from a superclass or mixin, - mark the class as abstract, or - provide a 'noSuchMethod' implementation. class NextPage extends StatefulWidget{ ^^^^^^^^ /C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart:925:9: Context: 'StatefulWidget.createState' is defined here. State createState(); ^^^^^^^^^^^ lib/main.dart:75:7: Error: The non-abstract class 'NextPage2' is missing implementations for these members: - StatefulWidget.createState Try to either - provide an implementation, - inherit an implementation from a superclass or mixin, - mark the class as abstract, or - provide a 'noSuchMethod' implementation. class NextPage2 extends StatefulWidget{ ^^^^^^^^^ /C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart:925:9: Context: 'StatefulWidget.createState' is defined here. State createState(); ^^^^^^^^^^^ lib/main.dart:30:29: Error: 'setState' isn't a function or method and can't be invoked. setState((){ ^^^^^...
コード
//入力画面 import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } // ignore: must_be_immutable class MyApp extends StatefulWidget { String name; String setState; @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), home: Scaffold( appBar: AppBar( title: Text('入力画面'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ TextField( onChanged: (value) { setState((){ name = value; }); }, decoration: InputDecoration( hintText: 'ここに入力した値を次の画面に渡したい' ), ), TextField( decoration: InputDecoration( hintText: 'ここに入力した値を次の画面に渡したい' ), ), RaisedButton( child: Text('確認画面へ'), onPressed: (){ Navigator.push( context, MaterialPageRoute(builder: (context) => NextPage()), ); } ), ], ), ), ) ); } } //確認画面 class NextPage extends StatefulWidget{ @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), home: NextPage2(), ); } } class NextPage2 extends StatefulWidget{ NextPage2({this.name}); final String name; @override Widget build(BuildContext context){ return Scaffold( appBar: AppBar( title: Text('確認画面'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text(name), Text(name), ], ), ), ); } }
何が間違っているのかエラー見ても不明です。
どなたかアドバイスいただけませんでしょうか。
よろしくお願いいたします。
追記
//入力画面 import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } // ignore: must_be_immutable class MyApp extends StatefulWidget { String name; String phone; MyApp({Key key, this.name, this.phone}) : super(key: key); @override MyAppState createState() => MyAppState(); } class MyAppState extends State<MyApp> { Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), home: Scaffold( appBar: AppBar( title: Text('入力画面'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ TextField( onChanged: (value) { setState((){ name = value; }); }, decoration: InputDecoration( hintText: 'ここに入力した値を次の画面に渡したい' ), ), TextField( decoration: InputDecoration( hintText: 'ここに入力した値を次の画面に渡したい' ), ), RaisedButton( child: Text('確認画面へ'), onPressed: (){ Navigator.push( context, MaterialPageRoute(builder: (context) => NextPage()), ); } ), ], ), ), ) ); } } //確認画面 class NextPage extends StatefulWidget{ @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), home: NextPage2(), ); } } class NextPage2 extends StatefulWidget{ NextPage2({this.name}); final String name; @override Widget build(BuildContext context){ return Scaffold( appBar: AppBar( title: Text('確認画面'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text(name), Text(name), ], ), ), ); } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/23 14:05
2021/01/23 14:09
2021/01/23 14:14
2021/01/23 14:16