Исключение, перехваченное библиотекой виджетов BoxConstraints, имеет отрицательную минимальную ширину

#flutter #dart

#flutter #dart

Вопрос:

Итак, сегодня я запускаю эту программу

 class NumberVerifyPage extends StatefulWidget {
  static String page = 'number_verify';
  @override
  _NumberVerifyPageState createState() => _NumberVerifyPageState();
}

class _NumberVerifyPageState extends State<NumberVerifyPage>
    with TickerProviderStateMixin {
  AnimationController animationController;
  Animation animation;

  @override
  void initState() {
    animationController =
        AnimationController(vsync: this, duration: Duration(seconds: 3));
    animation = CurvedAnimation(
        parent: animationController, curve: Curves.elasticInOut);

    animationController.forward();

    animationController.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        animationController.reverse(from: 1.0);
      } else if (status == AnimationStatus.dismissed) {
        animationController.forward();
      }
    });

    animationController.addListener(() {
      setState(() {});
    });

    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return Scaffold(
      body: SafeArea(
        child: SizedBox(
          width: double.infinity,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Container(
                    padding: EdgeInsets.symmetric(
                        horizontal: getProportionateScreenWidth(20)),
                    width: animation.value * 200,
                    child: Image.asset('assets/images/doomapic.jpg'),
                  ),
                  Expanded(
                    child: Text(
                      'Hi There! Welcome  😉',
                      style:
                          TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
                    ),
                  )
                ],
              ),
              SizedBox(height: getProportionateScreenHeight(30)),
              SizedBox(height: SizeConfig.screenHeight * 0.08),
              Container(
                padding: EdgeInsets.only(left: 20, top: 35, right: 20),
                child: IntlPhoneField(
                  keyboardType: TextInputType.number,
                  decoration: InputDecoration(
                    hintText: 'Enter your Phone Numbers',
                    labelStyle: TextStyle(
                      fontFamily: 'Lato',
                      fontWeight: FontWeight.normal,
                    ),
                    focusedBorder: UnderlineInputBorder(
                      borderSide: BorderSide(
                        width: 1,
                        color: Colors.white,
                      ),
                    ),
                  ),
                ),
              ),
              SizedBox(height: SizeConfig.screenHeight * 0.1),
              BottomFlatButton(
                onTap: () {},
              )
            ],
          ),
        ),
      ),
    );
  }
}
 

и я получаю следующую ошибку
======== Исключение, обнаруженное библиотекой виджетов ========================================================
Следующее утверждение было брошено строительным контейнером (заполнение: EdgeInsets(20.9, 0.0, 20.9, 0.0), ограничения: BoxConstraints(w=-14.0, 0.0<= h<= Бесконечность; НЕ НОРМАЛИЗОВАНО), грязный):
BoxConstraints имеет отрицательную минимальную ширину.

Нарушающими ограничениями были: BoxConstraints(w =-14.0, 0.0<=h<= Бесконечность; НЕ НОРМАЛИЗОВАНО) Соответствующим виджетом, вызывающим ошибку, был: Контейнер file:///C:/Users/fredi/AndroidStudioProjects/dooma_app/lib/screens/otp_verify/number_verification_screen.dart:62:19Когда было сгенерировано исключение, это был стек: #0 BoxConstraints.debugAssertIsValid..throwError (пакет: flutter/src/rendering/box.dart:517:9) #1 BoxConstraints.debugAssertIsValid . (пакет: flutter / src/rendering/box.dart:546:19) #2 BoxConstraints.debugAssertIsValid (пакет: flutter / src /rendering/box.dart: 565:6) #3 new ConstrainedBox (пакет: flutter / src / widgets/basic.dart:2198:27)#4 Container.build (пакет: flutter/src/widgets/container.dart:430:17) …

Синхронизация файлов с AOSP устройства на эмуляторе IA…

Комментарии:

1. При запуске анимации ваш контейнер имеет ширину 0. Добавление дополнения означает, что оно будет иметь отрицательную ширину.

2. что мне тогда делать @Abion47

3. Вы можете попробовать добавить Math.min вызов, чтобы ширина никогда не была меньше заполнения.