フロント側をFlutter(スマホ)Thymeleaf(PC)、バックエンド側SpringBootの自動作成@自動生成ツール作成中
18:36
①ついに、flutter・スマホ側が動くかチェックした。直すところはそれなりに見えてきた。まだまだありそうだけど。
洗い出した内容
★Flutter側PGMのエラー ■メニューで「商品情報一覧(更新削除)」押下時にエラー発生 ①エラーログ: ======== Exception caught by widgets library ======================================================= The following NoSuchMethodError was thrown building Builder: The method '[]' was called on null. Receiver: null Tried calling: []("dbELEMENTS") The relevant error-causing widget was: MaterialApp MaterialApp:file:///C:/Users/ueki_/AndroidStudioProjects/flutter_app/lib/main.dart:20:12 When the exception was thrown, this was the stack: #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) #1 ShohinSrchForm.fromJson (package:flutter_app/form/shohin_srch_form.dart:89:45) #2 _ShohinListState.initState (package:flutter_app/affairs/shohin/shohin_list.dart:1250:21) 理由:shohinSrchFormなのに間違ってshohinFormとしていた。 修正する箇所:ShohinSrchFormのfromJsonメソッド <<修正前 start>> dbELEMENTS = _resDataMap["shohinForm"]["dbELEMENTS"]; <<修正前 end>> <<修正後 start>> dbELEMENTS = _resDataMap["shohinSrchForm"]["dbELEMENTS"]; <<修正後 end>> ②エラーログ: ======== Exception caught by widgets library ======================================================= The following _TypeError was thrown building Builder: type 'List<dynamic>' is not a subtype of type 'List<String>' The relevant error-causing widget was: MaterialApp MaterialApp:file:///C:/Users/ueki_/AndroidStudioProjects/flutter_app/lib/main.dart:20:12 When the exception was thrown, this was the stack: #0 ShohinSrchForm.fromJson (package:flutter_app/form/shohin_srch_form.dart:96:7) #1 _ShohinListState.initState (package:flutter_app/affairs/shohin/shohin_list.dart:1250:21) 理由:List<dynamic>で受け取っているので、List<String>には入れれないと言っている。 修正する箇所:ShohinSrchFormのfromJsonメソッド <<修正前 start>> openkbn1Array = _resDataMap["shohinSrchForm"]["openkbn1Array"] ?? []; // 公開区分 <<修正前 end>> <<修正後 start>> openkbn1Array = _resDataMap["shohinSrchForm"]["openkbn1Array"].cast<String>() ?? []; // 公開区分 <<修正後 end>> ③エラーログ ======== Exception caught by widgets library ======================================================= The following assertion was thrown building ShohinList(dirty, state: _ShohinListState#db59a): There should be exactly one item with [DropdownButton]'s value: 0. Either zero or 2 or more [DropdownMenuItem]s were detected with the same value 'package:flutter/src/material/dropdown.dart': Failed assertion: line 894 pos 15: 'items == null || items.isEmpty || value == null || items.where((DropdownMenuItem<T> item) { return item.value == value; }).length == 1' The relevant error-causing widget was: ShohinList ShohinList:file:///C:/Users/ueki_/AndroidStudioProjects/flutter_app/lib/home.dart:375:25 When the exception was thrown, this was the stack: #2 new DropdownButton (package:flutter/src/material/dropdown.dart:894:15) #3 _ShohinListState._makeCndsWidgets (package:flutter_app/affairs/shohin/shohin_list.dart:193:13) #4 _ShohinListState._makeWidgets (package:flutter_app/affairs/shohin/shohin_list.dart:105:16) #5 _ShohinListState.build (package:flutter_app/affairs/shohin/shohin_list.dart:77:21) 理由:biztypeCd=0だけど、ドロップダウンリストに0はないよって言っているようなので、 修正する箇所:ShohinListクラス、及び、ShohinRegisterAmendクラス <<修正前 start>> biztypeCdはintとして定義している。 例: late int biztypeCd; // 業種ID _shohinSrchForm.biztypeCd = value as int; など <<修正前 end>> <<修正後 start>> biztypeCdはStringとして定義する。 _shohinSrchForm.biztypeCd = value as String; そのほかの項目でintとしているものすべてStringに変更する。 Form全体で行う。 <<修正後 end>> ④エラーログ ======== Exception caught by widgets library ======================================================= The following _TypeError was thrown building ShohinList(dirty, state: _ShohinListState#f77a9): type 'List<List<String>>' is not a subtype of type 'Map<dynamic, dynamic>' The relevant error-causing widget was: ShohinList ShohinList:file:///C:/Users/ueki_/AndroidStudioProjects/flutter_app/lib/home.dart:375:25 When the exception was thrown, this was the stack: #0 CommUtils.publicELEMENTS (package:flutter_app/utils/comm_utils.dart:394:73) #1 CommUtils.publicELEMENTSList (package:flutter_app/utils/comm_utils.dart:403:32) #2 _ShohinListState._makeCndsWidgets (package:flutter_app/affairs/shohin/shohin_list.dart:389:35) 修正する箇所: ・ShohinListクラス <<修正前 start>> children: CommUtils.publicELEMENTSList('OPN_KBN', '全て', Elements.elements).map((e) => <<修正前 end>> <<修正後 start>> children: Elements.elementsList("OPN_KBN", "全て").map((e) => すべてのDBエレメント以外のエレメントはこれに変更する。 CommUtils.publicELEMENTSListは削除する。 <<修正後 end>> ・ElementsクラスelementsListメソッド static List<List<String>> elementsList(String key, String defaultStr) { <<修正前 start>> List<List<String>> list = [["", defaultStr]]; <<修正前 end>> <<修正後 start>> List<List<String>> list = [[]]; if (defaultStr.isNotEmpty) { list = [["", defaultStr]]; } <<修正後 end>> for (var element in elements[key]!) { ⑤エラーログ ======== Exception caught by widgets library ======================================================= The following _TypeError was thrown building ShohinList(dirty, state: _ShohinListState#56905): type 'String' is not a subtype of type 'DateTime' The relevant error-causing widget was: ShohinList ShohinList:file:///C:/Users/ueki_/AndroidStudioProjects/flutter_app/lib/home.dart:375:25 When the exception was thrown, this was the stack: #0 _ShohinListState._makeListWidgetItems (package:flutter_app/affairs/shohin/shohin_list.dart:915:62) #1 _ShohinListState._makeListWidgets (package:flutter_app/affairs/shohin/shohin_list.dart:721:25) 理由:DateFormat('yyyy/MM/dd HH:mm:ss').format(element["insdt"]),としているが、element["insdt"]はStringだ! さらに、なぜか、Springからの日付は標準時間(9時間前)なので9時間を加算する。 さらに、システム内の日付時間を日本にしておく。 修正する箇所: ・ShohinListクラス、及びShohinDetailクラス、ShohinRegisterAmendクラス <<追加 start>> import 'package:intl/date_symbol_data_local.dart'; <<追加 end>> ・・・ Widget build(BuildContext context) { <<追加 start>> initializeDateFormatting("ja_JP"); <<追加 end>> <<修正前 start>> if (element["insdt"] != null) { <<修正前 end>> <<修正後 start>> if (element["insdt"].isNotEmpty) { ・・・すべてのelement["・・・"]に対して行う <<修正後 end>> <<修正前 start>> DateFormat('yyyy/MM/dd HH:mm:ss').format(element["insdt"]), <<修正前 end>> <<修正後 start>> DateFormat('yyyy/MM/dd HH:mm:ss').format((DateTime.parse(element["insdt"])).add(const Duration(hours:9))), ・・・すべての、DateFormatをおこなうelement["・・・"]に対して行う <<修正後 end>> ⑥検索ボタン押下したら、 ”エラーが発生しましたtype 'int' is not a subtype of type 'String'”というエラー文言が画面トップに赤文字で表示された。 ・理由:ShohinSrchFormクラス、ShohinFormクラスでSpringからの戻りが数字の時、Stringに変換できないみたいだ。 <<修正前 start>> biztypeCd = _resDataMap["shohinSrchForm"]["biztypeCd"] ?? ""; // 業種ID <<修正前 end>> biztypeCd = _resDataMap["shohinSrchForm"]["biztypeCd"]!=null?_resDataMap["shohinSrchForm"]["biztypeCd"].toString():""; // 業種ID <<修正後 start>> <<修正後 end>> ・エラーメッセージに例外発生のメッセージが出ているのを修正する ShohinListクラス、及びShohinDetailクラス、ShohinRegisterAmendクラス <<修正前 start>> _errorSuccessMsg = "エラーが発生しました" + e.toString(); <<修正前 end>> <<修正後 start>> if (kDebugMode) { print("エラーが発生しました" + e.toString()); } _errorSuccessMsg = "内部エラーが発生しました"; <<修正後 end>> ⑦日付の範囲検索が1行に収まり切れなかった。 さらに、日付項目が任意入力の時、日付選択ボタンの右側に、「クリア」ボタンを付け、押下により日付をクリアする。 ・ShohinListクラス、ShohinRegisterAmendクラス 例:ひな形「hinagata_ListSrch_年月日FromTo02.txt」修正 ・・・ children: <Widget>[ // 日付の入力フォーム const Text("■{ITEM_NAME_KANJI}■", overflow: TextOverflow.clip, ), <<追加 start>> Row ( children: <Widget>[ <<追加 end>> Container( ・・・ ), Container( ・・・ ), <<追加 start>> Container( margin: const EdgeInsets.fromLTRB(5, 0, 5, 5), padding: const EdgeInsets.fromLTRB(5, 0, 5, 0), child: ElevatedButton( onPressed: () async { setState(() { _shohinSrchForm.■{ITEM_NAME}■From = null; }); }, style: ElevatedButton.styleFrom( primary: Colors.blue, ), child: const Text("クリア"), ), ), ] ), <<追加 end>> Text(' ~ ', ), <<ここに移動した start>> Row ( children: <Widget>[ <<ここに移動した end>> Container( ・・・ ), Container( ・・・ ), <<追加 start>> Container( margin: const EdgeInsets.fromLTRB(5, 0, 5, 5), padding: const EdgeInsets.fromLTRB(5, 0, 5, 0), child: ElevatedButton( onPressed: () async { setState(() { _shohinSrchForm.■{ITEM_NAME}■To = null; }); }, style: ElevatedButton.styleFrom( primary: Colors.blue, ), child: const Text("クリア"), ), ), <<追加 end>> ] ), Text( ・・・ ⑧日付の範囲検索で日付指定したら、HTTP送信まえに例外発生 発生した例外:Converting object to an encodable object failed: Instance of 'DateTime' 理由:ShohinSrchFormクラス、ShohinFormクラスでSpringからの戻りがDateの時、DateTimeに変換できないみたいだ。 ・・・これは調査してから修正する。
とりあえず今の画面
■2022/06/15に、勉強した成果:『Flutter_JavaSpringプログラム自動作成◎自動生成ツール』をVectorに載せました。Zenn本も書きました。使ってみての感想や間違いの指定や、こうやったほうがいいとかの情報があればメールください。
・Vector
www.vector.co.jp
・Zenn本(Flutter_JavaSpringプログラム自動作成)
zenn.dev