Android 我在flifter中遇到了一个问题:下面的断言是在构建TextField时抛出的,它使我感到一个陌生的问题

Android 我在flifter中遇到了一个问题:下面的断言是在构建TextField时抛出的,它使我感到一个陌生的问题,android,dart,flutter,widget,Android,Dart,Flutter,Widget,我在flifter中遇到了一个问题:下面的断言被抛出到building TextField中,它让我感到了一个奇怪的问题,就在一瞬间 对于任何关于代码或错误的澄清,请在下面进行评论,我将在几分钟后回复,因为我迫不及待地要解决这个问题,并在没有太多想法的情况下继续前进 我是一个意大利男孩,非常熟悉flifter的编程,我从这门课程开始。你是我唯一能称呼的人。我将为任何能解决这个“问题”的人提供一份玛格丽塔比萨饼 Andoid Studio返回给我的错误如下: I/flatter(26182):以下

我在flifter中遇到了一个问题:下面的断言被抛出到building TextField中,它让我感到了一个奇怪的问题,就在一瞬间

对于任何关于代码或错误的澄清,请在下面进行评论,我将在几分钟后回复,因为我迫不及待地要解决这个问题,并在没有太多想法的情况下继续前进

我是一个意大利男孩,非常熟悉flifter的编程,我从这门课程开始。你是我唯一能称呼的人。我将为任何能解决这个“问题”的人提供一份玛格丽塔比萨饼

Andoid Studio返回给我的错误如下:

I/flatter(26182):以下断言被抛出 TextField(控制器:I/颤振(26182): 文本编辑控制器#e1688(文本编辑值(文本:┤├, 选择: text选择(基偏移量:-1,I/颤振(26182):扩展到Fset:-1, affinity:textafinity.down,isDirectional:false),组合: I/颤振(26182):文本范围(开始:-1,结束:-1)),启用:真, 装饰:输入装饰(hintText:“材料”),I/颤振(26182): 自动更正:true,强制的最大长度,onTap:null,dirty,state: _TextFieldState#73fdb):I/flatter(26182):未找到任何材料小部件。I/flatter(26182):TextField小部件需要一个Material小部件 祖先。I/flatter(26182):在材料设计中,大多数小部件 概念上“印刷”在一张材料上。在颤栗的I/颤栗中 (26182):材质库,该材质由 材料小部件。这是材料小部件I/flatter(26182):即 例如,渲染墨水飞溅。因此,许多材料 库小部件要求I/flatter(26182):存在一个材质 它们上面的树中的小部件。I/颤振(26182):引入 材质小部件,您可以直接包含一个,也可以使用一个小部件 包含I/flatter(26182):材质本身,如卡片, 对话框、抽屉或脚手架。I/flatter(26182):特定小部件 找不到物质祖先的是:I/flatter(26182):
文本字段(控制器: 文本编辑控制器#e1688(文本编辑值(文本:┤├, 选择: I/颤振(26182):文本选择(基偏移量:-1,扩展设置:-1, affinity:textafinity.down,isDirectional:I/flatter(26182):
false),组合:TextRange(开始:-1,结束:-1)),已启用:true, 装饰:I/flatter(26182):输入装饰(hintText:“material”), 自动更正:true,强制执行最大长度,onTap:null)I/颤振 (26182):此小部件的祖先是:

。。。还有一长串小部件

这是我的代码,一个非常简单的输入表单,包含两个表单,“Materiala”和“description”,以及从中加载到一个名为“AssegnoPage”的TabBarView中的页面。我使用的是作用域模型,您可以在下面找到它。ù

关注AssegnoPage的选项卡:AssegnoListPage和AggiungiAssegno

该页面:

导入“包装:颤振/材料.省道”;
导入“包:prova_app_book/assegno/page/aggiungi_assegno.dart”;导入“包:prova_app_book/widget/drawer.dart”;导入“assegno_list.dart”//导入“../models/assegno.dart”;
类AssegnoPage扩展了无状态小部件{
@覆盖小部件构建(构建上下文){
返回DefaultTabController(
长度:2,
孩子:脚手架(
抽屉:抽屉(子:抽屉Widget(),),
appBar:appBar(
标题:文本('Gestione Assegno'),
底部:选项卡栏(
选项卡:[
标签(
图标:图标(Icons.edit),
文本:“Aggiungi Assegno”,
),
标签(
图标:图标(Icons.book),
文字:“Il tuo assegno”,
),
],
),
),
正文:选项卡视图(子项:[
aggiungiassigno(),
AssegnoListPage()
]),
),
);   } }
表单的末尾带有submitbutton:

import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';

import '../../scoped_models/assegno.dart';
import '../../models/assegno.dart';

class AggiungiAssegno extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _AggiungiAssegnoState();
  }
}

class _AggiungiAssegnoState extends State<AggiungiAssegno> {
  final Map<String, dynamic> _formData = {
    'materia': null,
    'assegno': null,
  };
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

  Widget _buildTitoloMateria(Assegno assegno) {
    return TextFormField(
      decoration: InputDecoration(hintText: 'Materia'),
      initialValue: assegno == null ? '' : assegno.materia,
      validator: (String value) {
        if (value.isEmpty) {
          return 'Il nome della materia è necessario';
        }
      },
      onSaved: (String value) {
        _formData['materia'] = value;
      },
    );
  }

  Widget _buildAssegno(Assegno assegno) {
    return TextFormField(
      decoration: InputDecoration(hintText: 'Assegno'),
      maxLines: 3,
      initialValue: assegno == null ? '' : assegno.assegno,
      validator: (String value) {
        if (value.isEmpty) {
          return 'L\'assegno è necessario';
        }
      },
      onSaved: (String value) {
        _formData['assegno'] = value;
      },
    );
  }

  void _submitForm(Function aggiungiAssegno, Function aggiornaAssegno, [int selectedAssegnoIndex]) {
    if (!_formKey.currentState.validate()) {
      return;
    }
    _formKey.currentState.save();
    if (selectedAssegnoIndex == null) {
      aggiungiAssegno(Assegno(
          materia: _formData['materia'], assegno: _formData['assegno']));
    } else {
      aggiornaAssegno(
          Assegno(
              materia: _formData['materia'], assegno: _formData['assegno']));
    }
    Navigator.pushReplacementNamed(context, '/panoramica');
  }

  Widget _buildSubmitButton() {
    return ScopedModelDescendant<AssegnoModel>(
      builder: (BuildContext context, Widget child, AssegnoModel model) {
        return RaisedButton(
          child: Text('Fatto'),
          textColor: Colors.white,
          onPressed: () =>
              _submitForm(model.aggiungiAssegno, model.aggiornaAssegno, model.selectesAssegnoIndex),
        );
      },
    );
  }

  Widget _buildPageContent(BuildContext context, Assegno assegno) {
    final double deviceWidth = MediaQuery.of(context).size.width;
    final double targetWidth = deviceWidth > 550.0 ? 500.0 : deviceWidth * 0.95;
    final double targetPadding = deviceWidth - targetWidth;
    return Container(
      margin: EdgeInsets.all(10.0),
      child: Form(
        key: _formKey,
        child: ListView(
          padding: EdgeInsets.symmetric(horizontal: targetPadding / 2),
          children: <Widget>[
            _buildTitoloMateria(assegno),
            SizedBox(
              height: 20.0,
            ),
            _buildAssegno(assegno),
            SizedBox(
              height: 20.0,
            ),
            _buildSubmitButton(),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return ScopedModelDescendant<AssegnoModel>(
      builder: (BuildContext context, Widget child, AssegnoModel model) {
        final Widget pageContent = _buildPageContent(context, model.selectedAssegno);
        return model.selectesAssegnoIndex == null
            ? pageContent
            : Scaffold(
                appBar: AppBar(
                  title: Text('Aggiungi Assegno'),
                ),
                body: pageContent,
              );
      },
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:scoped_model/scoped_model.dart”;
导入“../../scoped_models/assegno.dart”;
导入“../models/assegno.dart”;
类AggiungiAssegno扩展StatefulWidget{
@凌驾
状态createState(){
返回_aggiungiassignostate();
}
}
类_aggiungiassignostate扩展状态{
最终地图_formData={
“materiala”:空,
“assegno”:null,
};
最终的GlobalKey _formKey=GlobalKey();
小部件_buildTitoloMaterial(Assegno Assegno){
返回TextFormField(
装饰:输入装饰(hintText:“Material”),
initialValue:assegno==null?'':assegno.materiala,
验证器:(字符串值){
if(value.isEmpty){
返回“必要的材料名称”;
}
},
onSaved:(字符串值){
_formData['Material']=值;
},
);
}
小部件_buildAssegno(Assegno Assegno){
返回TextFormField(
装饰:输入装饰(hintText:“Assegno”),
maxLines:3,
initialValue:assegno==null?“”:assegno.assegno,
验证器:(字符串值){
if(value.isEmpty){
返回'L'assegnoènecessario';
}
},
onSaved:(字符串值){
_formData['assegno']=值;
},
);
}
void _submitForm(函数aggiungiAssegno,函数aggiornaAssegno,[int-selectedassegonindex]){
如果(!\u formKey.currentState.validate()){
返回;
}
_formKey.currentState.save();
如果(selectedAssegnoIndex==null){
aggiungiAssegno(Assegno(
材料:_formData['materia',assegno:_formData['assegno']);
}否则{
阿吉奥纳萨尼奥(
阿塞尼奥(
材料:_formData['materia',assegno:_formData['assegno']);
}
pushReplacementNamed(上下文'/panoramica');
}
小部件_buildSubmitButton(){
返回范围modeldescendant(
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';

import '../../scoped_models/assegno.dart';
import '../../models/assegno.dart';

class AggiungiAssegno extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _AggiungiAssegnoState();
  }
}

class _AggiungiAssegnoState extends State<AggiungiAssegno> {
  final Map<String, dynamic> _formData = {
    'materia': null,
    'assegno': null,
  };
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

  Widget _buildTitoloMateria(Assegno assegno) {
    return TextFormField(
      decoration: InputDecoration(hintText: 'Materia'),
      initialValue: assegno == null ? '' : assegno.materia,
      validator: (String value) {
        if (value.isEmpty) {
          return 'Il nome della materia è necessario';
        }
      },
      onSaved: (String value) {
        _formData['materia'] = value;
      },
    );
  }

  Widget _buildAssegno(Assegno assegno) {
    return TextFormField(
      decoration: InputDecoration(hintText: 'Assegno'),
      maxLines: 3,
      initialValue: assegno == null ? '' : assegno.assegno,
      validator: (String value) {
        if (value.isEmpty) {
          return 'L\'assegno è necessario';
        }
      },
      onSaved: (String value) {
        _formData['assegno'] = value;
      },
    );
  }

  void _submitForm(Function aggiungiAssegno, Function aggiornaAssegno, [int selectedAssegnoIndex]) {
    if (!_formKey.currentState.validate()) {
      return;
    }
    _formKey.currentState.save();
    if (selectedAssegnoIndex == null) {
      aggiungiAssegno(Assegno(
          materia: _formData['materia'], assegno: _formData['assegno']));
    } else {
      aggiornaAssegno(
          Assegno(
              materia: _formData['materia'], assegno: _formData['assegno']));
    }
    Navigator.pushReplacementNamed(context, '/panoramica');
  }

  Widget _buildSubmitButton() {
    return ScopedModelDescendant<AssegnoModel>(
      builder: (BuildContext context, Widget child, AssegnoModel model) {
        return RaisedButton(
          child: Text('Fatto'),
          textColor: Colors.white,
          onPressed: () =>
              _submitForm(model.aggiungiAssegno, model.aggiornaAssegno, model.selectesAssegnoIndex),
        );
      },
    );
  }

  Widget _buildPageContent(BuildContext context, Assegno assegno) {
    final double deviceWidth = MediaQuery.of(context).size.width;
    final double targetWidth = deviceWidth > 550.0 ? 500.0 : deviceWidth * 0.95;
    final double targetPadding = deviceWidth - targetWidth;
    return Container(
      margin: EdgeInsets.all(10.0),
      child: Form(
        key: _formKey,
        child: ListView(
          padding: EdgeInsets.symmetric(horizontal: targetPadding / 2),
          children: <Widget>[
            _buildTitoloMateria(assegno),
            SizedBox(
              height: 20.0,
            ),
            _buildAssegno(assegno),
            SizedBox(
              height: 20.0,
            ),
            _buildSubmitButton(),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return ScopedModelDescendant<AssegnoModel>(
      builder: (BuildContext context, Widget child, AssegnoModel model) {
        final Widget pageContent = _buildPageContent(context, model.selectedAssegno);
        return model.selectesAssegnoIndex == null
            ? pageContent
            : Scaffold(
                appBar: AppBar(
                  title: Text('Aggiungi Assegno'),
                ),
                body: pageContent,
              );
      },
    );
  }
}
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';

//import '../../models/assegno.dart';
import 'aggiungi_assegno.dart';
import '../../scoped_models/assegno.dart';

class AssegnoListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ScopedModelDescendant<AssegnoModel>(
      builder: (BuildContext context, Widget child, AssegnoModel model) {
        return ListView.builder(
          itemBuilder: (BuildContext context, int index) {
            return Column(
              children: <Widget>[
                ListTile(
                  leading: Icon(Icons.book),
                  title: Text(model.assegno[index].materia),
                  trailing: IconButton(
                      icon: Icon(Icons.edit),
                      onPressed: () {
                        model.selectAssegno(index);
                        Navigator.of(context).push(
                          MaterialPageRoute(
                            builder: (BuildContext context) {
                              return AggiungiAssegno();
                            },
                          ),
                        );
                      }),
                ),
                Divider(),
              ],
            );
          },
          itemCount: model.assegno.length,
        );
      },
    );
  }
}
import 'package:scoped_model/scoped_model.dart';

import '../models/assegno.dart';

class AssegnoModel extends Model{
  List <Assegno> _assegno = [];
  int _selectesAssegnoIndex;

  List<Assegno> get assegno{
    return List.from(_assegno);
  }

  int get selectesAssegnoIndex {
    return _selectesAssegnoIndex;
  }

  Assegno get selectedAssegno{
    if(_selectesAssegnoIndex == null){
      return null;
    }
    return _assegno[_selectesAssegnoIndex];
  }

  void aggiungiAssegno(Assegno assegno) {
      _assegno.add(assegno);
      _selectesAssegnoIndex = null;
    //print(_assegno);
  }

  void aggiornaAssegno(Assegno assegno) {
      _assegno[_selectesAssegnoIndex] = assegno;
      _selectesAssegnoIndex = null;
  }

  void eliminaAssegno() {
      _assegno.removeAt(_selectesAssegnoIndex);
      _selectesAssegnoIndex = null;
  }

  void selectAssegno(int index){
    _selectesAssegnoIndex = index;
  }
}
Material(
  child: TextField(...),
)