■解決したいこと
Flutter(Dart)を用いて簡単なアプリ開発を行っています。
ボタンを押すと次の画面に画面遷移するようなコードを記載したいのですが、
下記の様なエラーが出ております。
何かヒントとなる様なことがございましたら教えていただけますと幸いです。
■エラー内容
iterm
1 2I/flutter (23646): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════ 3I/flutter (23646): The following assertion was thrown while handling a gesture: 4I/flutter (23646): Navigator operation requested with a context that does not include a Navigator. 5I/flutter (23646): The context used to push or pop routes from the Navigator must be that of a widget that is a 6I/flutter (23646): descendant of a Navigator widget. 7I/flutter (23646): 8I/flutter (23646): When the exception was thrown, this was the stack: 9I/flutter (23646): #0 Navigator.of.<anonymous closure> (package:flutter/src/widgets/navigator.dart:2190:9) 10I/flutter (23646): #1 Navigator.of (package:flutter/src/widgets/navigator.dart:2197:6) 11I/flutter (23646): #2 Navigator.push (package:flutter/src/widgets/navigator.dart:1801:22) 12I/flutter (23646): #3 CookApp.build.<anonymous closure> (package:mytodoapp/main.dart:27:29) 13I/flutter (23646): #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19) 14I/flutter (23646): #5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38) 15I/flutter (23646): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24) 16I/flutter (23646): #7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11) 17I/flutter (23646): #8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5) 18I/flutter (23646): #9 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:219:7) 19I/flutter (23646): #10 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:477:9) 20I/flutter (23646): #11 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:78:12) 21I/flutter (23646): #12 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:124:9) 22I/flutter (23646): #13 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8) 23I/flutter (23646): #14 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:122:18) 24I/flutter (23646): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:108:7) 25I/flutter (23646): #16 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:220:19) 26I/flutter (23646): #17 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22) 27I/flutter (23646): #18 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7) 28I/flutter (23646): #19 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7) 29I/flutter (23646): #20 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7) 30I/flutter (23646): #24 _invoke1 (dart:ui/hooks.dart:267:10) 31I/flutter (23646): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5) 32I/flutter (23646): (elided 3 frames from dart:async) 33I/flutter (23646): 34I/flutter (23646): Handler: "onTap" 35I/flutter (23646): Recognizer: 36I/flutter (23646): TapGestureRecognizer#aaa22 37I/flutter (23646): ════════════════════════════════════════════════════════════════════════════════════════════════════ 38I/flutter (23646): Another exception was thrown: Navigator operation requested with a context that does not include a Navigator. 39I/flutter (23646): Another exception was thrown: Navigator operation requested with a context that does not include a Navigator. 40 41
main.dart
1import 'package:flutter/material.dart'; 2import 'package:mytodoapp/add_recipe_page.dart'; 3 4void main() => runApp(CookApp()); 5 6class CookApp extends StatelessWidget { 7 var titleText = 'cookapp'; 8 9 @override 10 Widget build(BuildContext context) { 11 return MaterialApp( 12 home: Scaffold( 13 appBar: AppBar( 14 leading: Icon(Icons.menu), 15 title: Text('レシピ一覧'), 16 ), 17 body: Container( 18 child: Center( 19 child: Column(children: <Widget>[ 20 Text(titleText), 21 22 RaisedButton( 23 child: Text("Button"), 24 color: Colors.orange, 25 textColor: Colors.white, 26 onPressed: () { 27 Navigator.push( 28 context, 29 MaterialPageRoute(builder: (context) => AddRecipe()), 30 ); 31 }, 32 ), 33 ]), 34 ), 35 ), 36 ), 37 ); 38 } 39} 40
add_recipe.dart(main.dartからの画面遷移先)
1 2import 'package:flutter/material.dart'; 3//import 'package:mytodoapp/main.dart'; 4 5//main関数は必ず記載する 6void main() => runApp(AddRecipe()); 7 8class AddRecipe extends StatelessWidget { 9 @override 10 Widget build(BuildContext context) { 11 return MaterialApp( 12 home: Scaffold( 13 //scaffoldの中でappBarを使用 14 appBar: AppBar( 15 title: Text('レシピ追加画面'), 16 leading: Icon(Icons.add_alert), 17 ), 18 body: Container( 19 child: Center( 20 child: Text('レシピ追加'), 21 ), 22 ), 23 ), 24 ); 25 } 26} 27
追記すべき情報があればご教示いただければと思います。
何卒宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/09/27 17:30
2020/09/27 23:51
2020/09/28 01:53