Flutter Web 构建屏幕时,Textfield 导致无休止的重复错误

Textfield causes endless repeating error when building the screen Flutter Web

在我导航到的屏幕中包含文本字段时,我遇到了一个奇怪的错误。 从 ProductsScreen 我有一个按钮可以推动 NewEditProductScreenProductBloc 传递给它。通常 Navigator.push 我用来将 bloc 传递到下一个屏幕的方式..

onPressed: () {
                                          Navigator.push(
                                            context,
                                            MaterialPageRoute(
                                              builder: (_) =>
                                                  BlocProvider.value(
                                                value: BlocProvider.of<
                                                    ProductBloc>(context),
                                                child: NewEditProductScreen(
                                                    type: 'New',
                                                    user: widget.user,
                                                    cityDb: widget.cityDb,
                                                    regionDb: widget.regionDb,
                                                    countryDb:
                                                        widget.countryDb),
                                              ),
                                            ),
                                          );
                                        }

出于某种原因,在 NewEditProductScreen 中使用 Textfield 会引发无限系列错误,但由于最后的状态打印是正确的,我猜问题不在 bloc 本身,事实上,如果我评论它们没有更多的错误。 该应用程序将在网络和设备上 运行 显示正确的文本字段..

你能看出我在这个屏幕上做错了什么吗?非常感谢。

class NewEditProductScreen extends StatefulWidget {
  final FixitUser user;
  final String cityDb;
  final String regionDb;
  final String countryDb;
  final String type;
  final Product product;

  const NewEditProductScreen(
      {Key key,
      this.type,
      this.product,
      this.user,
      this.cityDb,
      this.regionDb,
      this.countryDb})
      : super(key: key);

  @override
  _NewEditProductScreenState createState() => _NewEditProductScreenState();
}

class _NewEditProductScreenState extends State<NewEditProductScreen> {
  AutoSizeGroup autoSizeGroup = AutoSizeGroup();
  TextEditingController idController = TextEditingController();

  String productId = '';
  String productName = '';
  String brand = '';
  String price = '';
  String productDescription = '';
  String category = '';
  bool isPromotion = false;
  String vendor = '';
  String barcode = '';
  String imageUrl = '';
  Image productImage;
//  Uint8List imageData;
  int minimumStock = 0;
  int availableQuantity = 0;
  int soldQuantity = 0;
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
//    return BlocProvider<ProductBloc>(
//      create: (context) => ProductBloc(),
//      lazy: false,
//      child: BlocBuilder<ProductBloc, ProductState>(
    return BlocBuilder<ProductBloc, ProductState>(
      builder: (context, state) => MultiBlocListener(
        listeners: [
          BlocListener<ProductBloc, ProductState>(
              listener: (BuildContext context, ProductState state) {
            if (state is PickedImage) {
              setState(() {
//                productImage = Image.memory(state.imageData);
//                imageData = state.imageData;
              });
            }
            if (state is ProductSaved) {
              Navigator.pop(context);
            }
          }),
        ],
        child: Scaffold(
          body: Container(
            color: Colors.black54,
//          key: widget.key,
            padding: EdgeInsets.symmetric(horizontal: 100, vertical: 50),
            child: Container(
              decoration: BoxDecoration(
                color: Colors.transparent,
                borderRadius: BorderRadius.circular(5),
                border: Border.all(color: Colors.redAccent, width: 2),
              ),
              padding: EdgeInsets.all(20),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
//              Expanded(
//                child: productImage,
//              ),
                  SizedBox(height: 10),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      AutoSizeText(
                        AppLocalizations.instance.text('Product id'),
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 15,
                            fontWeight: FontWeight.w500),
                        minFontSize: 8,
                        maxLines: 1,
                        group: autoSizeGroup,
                      ),
                      UniversalPlatform.isWeb
                          ? TextField(
                              readOnly: true,
                              keyboardType: TextInputType.numberWithOptions(),
                              textDirection: TextDirection.ltr,
                              autofocus: true,
                              controller: idController,
                              onChanged: (value) {
                                idController.text = value;
                              },
                            )
                          : UniversalPlatform.isIOS
                              ? CupertinoTextField(
                                  readOnly: true,
                                  keyboardType:
                                      TextInputType.numberWithOptions(),
                                  controller: idController,
                                  onChanged: (value) {
                                    idController.text = value;
                                  },
                                )
                              : TextField(
                                  readOnly: true,
                                  keyboardType:
                                      TextInputType.numberWithOptions(),
                                  textDirection: TextDirection.ltr,
                                  autofocus: true,
                                  controller: idController,
                                  onChanged: (value) {
                                    idController.text = value;
                                  },
                                ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      FlatButton(
                          color: Colors.orangeAccent,
                          child: AutoSizeText(
                            AppLocalizations.instance.text('Cancel'),
                            style: TextStyle(fontSize: 30, color: Colors.white),
                            minFontSize: 8,
                            maxLines: 1,
                            group: autoSizeGroup,
                          ),
                          onPressed: () {
                            Navigator.pop(context);
                          }),
                    ],
                  )
                ],
              ),
            ),
          ),
        ),
      ),
//      ),
    );
  }

  @override
  void dispose() {
    idController.dispose();
    super.dispose();
  }
}

这是来自 Chrome 控制台的无限重复错误:

BlocTransaction is Transition { currentState: Instance of 'minified:RS', event: LoadOrders {user: User { displayName: zazza zenigata, email: zazza.zenigata.1976@gmail.com, phone number:, uid: eT9FWzlOgYfAIHZNh3bd28Ay4x32, photoUrl: https://lh3.googleusercontent.com/-8UmwYDOTbQg/AAAAAAAAAAI/AAAAAAAAAAA/AAKWJJOuSPI6gPocRgQMP_kIUFaFdTT_LA/s96-c/photo.jpg}}, nextState: LoadedProducts{ number of products: 0} }
2js_primitives.dart:49 Another exception was thrown: Instance of 'minified:bj<void>'
js_primitives.dart:49 Attempted to build a minified:XI, but it already has an HTML element FLT-OFFSET.
js_primitives.dart:49 Throw of null.
    at Object.f (http://localhost:5000/main.dart.js:1788:3)
    at XI.bT (http://localhost:5000/main.dart.js:21735:26)
    at XI.bT (http://localhost:5000/main.dart.js:21771:6)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
js_primitives.dart:49 Attempted to build a minified:XI, but it already has an HTML element FLT-OFFSET.
js_primitives.dart:49 Throw of null.
    at Object.f (http://localhost:5000/main.dart.js:1788:3)
    at XI.bT (http://localhost:5000/main.dart.js:21735:26)
    at XI.bT (http://localhost:5000/main.dart.js:21771:6)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
js_primitives.dart:49 Attempted to build a minified:XI, but it already has an HTML element FLT-OFFSET.
js_primitives.dart:49 Throw of null.
    at Object.f (http://localhost:5000/main.dart.js:1788:3)
    at XI.bT (http://localhost:5000/main.dart.js:21735:26)
    at XI.bT (http://localhost:5000/main.dart.js:21771:6)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
js_primitives.dart:49 Attempted to build a minified:XN, but it already has an HTML element FLT-PICTURE.
js_primitives.dart:49 Throw of null.
    at Object.f (http://localhost:5000/main.dart.js:1788:3)
    at XN.bT (http://localhost:5000/main.dart.js:21735:26)
    at XN.bT (http://localhost:5000/main.dart.js:21628:6)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)
    at XK.bT (http://localhost:5000/main.dart.js:21778:8)
    at XI.bT (http://localhost:5000/main.dart.js:21778:8)

找到问题了。它没有包含在扩展小部件中..现在一切正常..