flutter で 画面切替の処理をするのに、参考例とかを見て簡単なのを作ったが、この書き方では画面が切り替わらない。どこの書き方が間違っているのか?
主画面で Test Input に文字『q』を入れると、navigator.pushName が動くようにしているが、これではだめなのか?
import 'package:flutter/material.dart'; //import "package:intl/intl.dart"; // (DateFormat('MM/dd/yyyy HH:mm:ss::SS') に必要 import 'package:flutter/services.dart' show rootBundle; void main() { runApp(new MyApp());} class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'RoutesTest', //home: MyInit(), initialRoute: '/', routes: { '/': (context) => MyApp_Pejv(), '/second': (context) => MyInit(), }, ); } } class MyInit extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Init', home: MyInitForm(), ); } } // Define a custom Form widget. class MyInitForm extends StatefulWidget { @override _MyInitFormState createState() => _MyInitFormState(); } class _MyInitFormState extends State<MyInitForm> { @override Widget build(BuildContext context) { final searchText = new Flexible( child: TextField( //controller: myInitController, ), ); return Scaffold( appBar: AppBar( title: Text("init_set"), leading: BackButton( color: Colors.white, ) ), body: Center(child: Text("exam: font_set")), floatingActionButton: FloatingActionButton( child: Icon(Icons.android), onPressed: () => Navigator.pushNamed( context, '/', ), ), ); } } class MyApp_Pejv extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'test', home: MyPejvForm(), ); } } class MyPejvForm extends StatefulWidget { @override _MyPejvFormState createState() => _MyPejvFormState(); } class _MyPejvFormState extends State<MyPejvForm> { final myController = TextEditingController(); @override void dispose() { // Clean up the controller when the widget is disposed. myController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final searchText = new Flexible( child: TextField( controller: myController, onChanged: (String vorto) { if (vorto == "q") { print("changed ini vorto=" + vorto + "=="); Navigator.pushNamed( context, '/second', ); } }, ), ); return Scaffold( appBar: AppBar( title: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Text(" Test Input:"), SizedBox(width: 5), searchText, ]), ), body: Text("Input"), ); } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/08 08:32