前提
TODOアプリを作成しています。
onPressedを使って画面遷移したいのですが、エラー表示になってしまいます。
エラー文を読んでも解決できない状態です。
実現したいこと
onPressedを使って画面遷移したい
todo_list_pageからedit_todo_pageへ画面遷移
発生している問題・エラーメッセージ
error: The argument type 'void Function()' can't be assigned to the parameter type 'void Function(BuildContext)?'. (argument_type_not_assignable at [flutter_training_app1] lib/presentation/todo_list/todo_list_page.dart:44) error: The values in a const list literal must be constants. (non_constant_list_element at [flutter_training_app1] lib/presentation/todo_list/todo_list_page.dart:44) error: Invalid constant value. (invalid_constant at [flutter_training_app1] lib/presentation/todo_list/todo_list_page.dart:44) error: The method 'edit_todo_page' isn't defined for the type 'TodoListPage'. (undefined_method at [flutter_training_app1] lib/presentation/todo_list/todo_list_page.dart:48)
該当のソースコード
dart言語 : todo_list_page
import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_training_app1/domin/todo.dart'; import 'package:flutter_training_app1/presentation/add_todo/add_todo_page.dart'; import 'package:flutter_training_app1/presentation/todo_list/todo_list_model.dart'; import 'package:provider/provider.dart'; class TodoListPage extends StatelessWidget { @override Widget build(BuildContext context) { return ChangeNotifierProvider<TodoListModel>( create: (_) => TodoListModel()..fetchTodos(), child: Scaffold( appBar: AppBar( title: Text('todo list page'), ), body: Consumer<TodoListModel>( builder: (context, model, child) { final todos = model.todos; final listTiles = todos .map( (todo) => Slidable( child: ListTile( title: Text(todo.title), ), key: const ValueKey(0), // The start action pane is the one at the left or the top side. endActionPane: ActionPane( // A motion is a widget used to control how the pane animates. motion: const ScrollMotion(), // A pane can dismiss the Slidable. dismissible: DismissiblePane(onDismissed: () {}), // All actions are defined in the children parameter. children: const [ // A SlidableAction can have an icon and/or a label. SlidableAction( backgroundColor: Color(0xFF21B7CA), foregroundColor: Colors.white, icon: Icons.edit, label: '編集', //エラー箇所↓ onPressed: () async { //指定した画面に遷移する await Navigator.of(context).push( MaterialPageRoute( builder: (context){ return edit_todo_page(); }, ), ); }, ), //エラー箇所↑ SlidableAction( backgroundColor: Color(0xFFFE4A49), foregroundColor: Colors.white, icon: Icons.delete, label: '削除', onPressed: null, ), ], ), ), ) .toList(); return ListView( children: listTiles, ); }, ), floatingActionButton: Consumer<TodoListModel>(builder: (context, model, child) { return FloatingActionButton( child: Icon(Icons.add), onPressed: () async { // todo await Navigator.push( context, MaterialPageRoute( builder: (context) => AddTodoPage(), fullscreenDialog: true, ), ); model.fetchTodos(); }, ); }), ), ); } }

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。