Утилита Flutter Screen - метод 'setSp' был вызван на нуль - PullRequest
0 голосов
/ 24 апреля 2020

Изо дня в день я получаю такую ​​ошибку, я ничего не менял в своем коде. Я использую именно flutter_screenutil: ^ 1.0.2.

Когда я смотрел в Интернете, мне кажется, что все было сделано правильно. Я сделал инициализацию, даже попытался изменить ее параметры, но это ничего не дало. Я совершенно не знаю, что происходит, потому что компилятор говорит, что я должен заменить метод точно так же, и ничего не работает

Код:

import 'package:flutter_screenutil/flutter_screenutil.dart';

...


Widget customcard(String category, String description, String image){
    ScreenUtil.init(context);
    return Padding(
      padding: EdgeInsets.all( 20.0),
      child: InkWell(
        onTap: (){
          Navigator.of(context).pushReplacement(MaterialPageRoute(
            builder: (context) => getjason(category),
          ));
        },
        child: Material(
          color: Colors.white,
          elevation:  0.0,
          borderRadius: BorderRadius.circular(30.0),
          child: Container(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.symmetric(
                    vertical: 10,
                  ),
                  child:  Material(
                    elevation: 0.0,
                    borderRadius: BorderRadius.circular(30.0),
                    child:  Container(
                      height: 800.h,
                      width: 900.w,
                      child: ClipOval(
                        child: Image(
                          fit: BoxFit.cover,
                          image: AssetImage(
                            image,
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
                Center(
                  child: Text(
                    category,
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(90),
                      color: Colors.black87,
                      fontFamily: "Lato-Regular"
                    ),
                  ),
                ),
                Container(
                  padding: EdgeInsets.all(20.0),
                  child: Text(
                    description,
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(50),
                      fontFamily: "Lato-Italic",
                      color: Colors.black45,
                    ),
                    maxLines: 5,
                    textAlign: TextAlign.justify,
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

Ошибка:

The method 'setSp' was called on null.
Receiver: null
Tried calling: setSp(70)
...