当我尝试将GenerateReportView类中存在的ID添加到_GenerateReportViewState类中定义的映射中时,出现错误,请帮助我解决此问题,请在映射中的“ ID”键中添加当前值在父类的ID中。
class GenerateReportView extends StatefulWidget {
final String reportType;
final Map jsonString;
final String reportName;
final String dateType;
final String id;
final String language;
GenerateReportView(
{@required this.id,
@required this.language,
@required this.jsonString,
@required this.reportType,
@required this.reportName})
: dateType = jsonString['dateType'];
@override
_GenerateReportViewState createState() => _GenerateReportViewState();
}
class _GenerateReportViewState extends State<GenerateReportView>
with SingleTickerProviderStateMixin {
TabController _TabController;
String currentReportChartType;
List<TextEditingController> controllers = [];
TextEditingController controller;
Future report;
Map<String, dynamic> reqFormat = {"lang": "EN","id":widget.id};//here I am getting error saying "Only static members can be accessed in initializers."
答案 0 :(得分:1)
您可以在initState()中初始化
代码段
class _GenerateReportViewState extends State<GenerateReportView> with SingleTickerProviderStateMixin {
TabController _TabController;
String currentReportChartType;
List<TextEditingController> controllers = [];
TextEditingController controller;
Future report;
Map<String, dynamic> reqFormat;
@override
void initState() {
reqFormat = {"lang": "EN","id":widget.id};
super.initState();
}
答案 1 :(得分:0)
在承包商中插入ID并将其传递给
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class GenerateReportView extends StatefulWidget {
final String reportType;
final Map jsonString;
final String reportName;
final String dateType;
final String id;
final String language;
GenerateReportView(this.id, this.language, this.jsonString, this.reportType, this.reportName)
: dateType = jsonString['dateType'];
@override
_GenerateReportViewState createState() => _GenerateReportViewState(id);
}
class _GenerateReportViewState extends State<GenerateReportView>
with SingleTickerProviderStateMixin {
TabController _TabController;
String currentReportChartType;
List<TextEditingController> controllers = [];
TextEditingController controller;
Future report;
final String id;
Map<String, dynamic> reqFormat;
_GenerateReportViewState(this.id) {
reqFormat = {"lang": "EN", "id": id};
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return null;
} //here I am getting error saying "Only static members can be accessed in initializers."
}
并且您不需要@required
,只需移除卷曲的括号