Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix issue with Late in flutter/dart

I have this code in flutter

late String firstHalf;
  late String secondHalf;

  bool hiddenText = true;
  double textHeight = Diamension.screenHeight / 5.63;

  @override
  void iniState() {
    super.initState();
    if (widget.text.length > textHeight) {
      firstHalf = widget.text.substring(0, textHeight.toInt());
      secondHalf =
          widget.text.substring(textHeight.toInt() + 1, widget.text.length);
    } else {
      firstHalf = widget.text;
      secondHalf = "";
    }
  }

from the code you will see that I initialized "secondHalf" but I kept getting this error in debug

Exception has occurred.
LateError (LateInitializationError: Field 'secondHalf' has not been initialized.)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Unless you copy-pasted wrong into StackOverflow, you have just missed a t

Try changing void iniState() { to void initState() {

You probably have this warning (as also noted by @julemand101):

The method doesn’t override an inherited method. Try updating this
class to match the superclass, or removing the override
annotation.dartoverride_on_non_overriding_member

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading