Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 错误:flatter/lib/ui/ui_dart_state.cc(177)]未处理的异常:type';双倍';不是类型为';字符串';内铸_Flutter_Dart_Flutter Hive - Fatal编程技术网

Flutter 错误:flatter/lib/ui/ui_dart_state.cc(177)]未处理的异常:type';双倍';不是类型为';字符串';内铸

Flutter 错误:flatter/lib/ui/ui_dart_state.cc(177)]未处理的异常:type';双倍';不是类型为';字符串';内铸,flutter,dart,flutter-hive,Flutter,Dart,Flutter Hive,我得到这个错误,我无法找出原因和地点。 我是一个新手,我正在使用hive db和provider创建一个资金管理应用程序。这是我的添加事务页面, 未处理的异常:“double”类型不是typecast中“String”类型的子类型 class _AddTransactionState extends State<AddTransaction> with TickerProviderStateMixin{ String transTitle; double transAmoun

我得到这个错误,我无法找出原因和地点。 我是一个新手,我正在使用hive db和provider创建一个资金管理应用程序。这是我的添加事务页面, 未处理的异常:“double”类型不是typecast中“String”类型的子类型

class _AddTransactionState extends State<AddTransaction> with TickerProviderStateMixin{
  String transTitle;
  double transAmount=0;
  DateTime transDate = DateTime.now();
  Future<void> _selectDate(BuildContext context) async {
    final DateTime pickedDate = await showDatePicker(
        context: context,
        initialDate: transDate,
        firstDate: DateTime(2010),
        lastDate: DateTime(2050));
    if (pickedDate != null && pickedDate != transDate)
      setState(() {
        transDate = pickedDate;
      });
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.black,
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 20, horizontal: 40),
        height: 550,
        decoration: BoxDecoration(
          color: Color(0xffE8816D),
          borderRadius: BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)),
        ),
        child: Column(
          children: <Widget>[
            Text("New TransactionDetails", style: kdropDownTextStyle.copyWith(decoration: TextDecoration.underline),),
            SizedBox(height: 50,),
            TextField(
              onChanged: (value){transTitle = "$value";
              print(transTitle);},
              decoration: kTextFieldDecoration.copyWith(
                  hintText: 'Enter new Transaction',
                  hintStyle: TextStyle(color: Colors.black54),
              ),
            ),
            SizedBox(height: 30),
            TextField(
              onChanged: (value){
                transAmount = double.parse("$value");
                print(transAmount);
              },
              keyboardType: TextInputType.number,
              decoration: kTextFieldDecoration.copyWith(
                hintText: 'Enter Amount',
                hintStyle: TextStyle(color: Colors.black54),
              ),
            ),

            SizedBox(height: 30),
            Text("${transDate.day}-${transDate.month}-${transDate.year}",
              style: GoogleFonts.kaushanScript(textStyle: TextStyle(fontSize: 30)),
            ),
            RaisedButton(
              onPressed: () => _selectDate(context),
              child: Text('Select date'),
            ),
            FlatButton(
                onPressed: (){
                  Provider.of<TransData>(context, listen: false).addToList(
                    Item(
                      transactionType: widget.transactionType,
                      categoryName: widget.categoryName,
                      amount: transAmount,
                      dateTime: transDate,
                      transName: transTitle,
                    ));
                  Navigator.pop(context);
                },
                child: Text("Add Transaction"),
            )
          ],
        ),
      ),
    );
  }
}
class\u AddTransactionState使用TickerProviderStateMixin扩展状态{
字符串转换标题;
双交叉安装=0;
DateTime transDate=DateTime.now();
Future\u selectDate(BuildContext上下文)异步{
final DateTime PickeDate=等待showDatePicker(
上下文:上下文,
初始日期:transDate,
firstDate:DateTime(2010年),
最后日期:日期时间(2050年);
if(pickedDate!=null&&pickedDate!=transDate)
设置状态(){
transDate=选定日期;
});
}
@凌驾
小部件构建(构建上下文){
返回容器(
颜色:颜色,黑色,
子:容器(
填充:边缘组。对称(垂直:20,水平:40),
身高:550,
装饰:盒子装饰(
颜色:颜色(0xffE8816D),
borderRadius:borderRadius.only(右上:半径.圆形(20),左上:半径.圆形(20)),
),
子:列(
儿童:[
Text(“New TransactionDetails”,样式:kdropDownTextStyle.copyWith(装饰:TextDecoration.underline)),
尺寸箱(高度:50,),
文本字段(
onChanged:(value){transTitle=“$value”;
打印(transTitle);},
装饰:kTextFieldDecoration.copyWith(
hintText:“输入新交易”,
hintStyle:TextStyle(颜色:Colors.black54),
),
),
尺寸箱(高度:30),
文本字段(
一旦更改:(值){
transAmount=double.parse(“$value”);
打印(转载);
},
键盘类型:TextInputType.number,
装饰:kTextFieldDecoration.copyWith(
hintText:“输入金额”,
hintStyle:TextStyle(颜色:Colors.black54),
),
),
尺寸箱(高度:30),
文本(${transDate.day}-${transDate.month}-${transDate.year}),
样式:GoogleFonts.kaushanScript(textStyle:textStyle(fontSize:30)),
),
升起的按钮(
按下时:()=>\u选择日期(上下文),
子项:文本(“选择日期”),
),
扁平按钮(
已按下:(){
Provider.of(context,listen:false).addToList(
项目(
transactionType:widget.transactionType,
categoryName:widget.categoryName,
金额:交易金额,
日期时间:transDate,
transName:transTitle,
));
Navigator.pop(上下文);
},
子项:文本(“添加事务”),
)
],
),
),
);
}
}
这是我的transaction.g.dart文件

class ItemAdapter extends TypeAdapter<Item> {
  @override
  final typeId = 1;
  @override
  Item read(BinaryReader reader) {
    var numOfFields = reader.readByte();
    var fields = <int, dynamic>{
      for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
    };
    return Item(
      transactionType: fields[0] as String,
      categoryName: fields[1] as String,
      transName: fields[2] as String,
      amount: fields[3] as double,
      dateTime: fields[4] as DateTime,
    );
  }

  @override
  void write(BinaryWriter writer, Item obj) {
    writer
      ..writeByte(5)
      ..writeByte(0)
      ..write(obj.transactionType)
      ..writeByte(1)
      ..write(obj.categoryName)
      ..writeByte(2)
      ..write(obj.transName)
      ..writeByte(3)
      ..write(obj.amount)
      ..writeByte(4)
      ..write(obj.dateTime);
  }
}
class ItemAdapter扩展了TypeAdapter{
@凌驾
最终类型ID=1;
@凌驾
项读取(二进制读取器){
var numofields=reader.readByte();
变量字段={
对于(var i=0;i