OpenFlutter / flutter_screenutil

Flutter screen adaptation, font adaptation, get screen information
https://pub.dartlang.org/packages/flutter_screenutil
Apache License 2.0
3.88k stars 494 forks source link

Error when keyboard shows up #381

Closed ElshiatyTube closed 2 years ago

ElshiatyTube commented 2 years ago

The following assertion was thrown building _MediaQueryFromWindow(state: _MediaQueryFromWindowState#a1453): 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5356 pos 14: '() { // check that it really is our descendant Element? ancestor = dependent._parent; while (ancestor != this && ancestor != null) ancestor = ancestor._parent; return ancestor == this; }()': is not true.

lianfanghua commented 2 years ago

Duplicate of https://github.com/OpenFlutter/flutter_screenutil/issues/380#issue-1218521381

ElshiatyTube commented 2 years ago

I fixed it temporarily by using 5.0.0+2 version and setting MaterialApp builder context to ScreenUtil, something like this:

ScreenUtilInit(
          builder: (_)=>MaterialApp(
            builder: (context, widget) {
              ScreenUtil.setContext(context);
              return widget!;
            },
            title: appName,
          )
      ),

Hope to fix the issue in the latest version

Mounir-Bouaiche commented 2 years ago

@ElshiatyTube @lianfanghua , Please try with master branch and tell us if it works with you so we can ship a stable version in pub.dev.

dependencies:

  flutter_screenutil:
    git:
      url: https://github.com/OpenFlutter/flutter_screenutil
      branch: master
ElshiatyTube commented 2 years ago

@Mounir-Bouaiche Great, it works fine.

Mounir-Bouaiche commented 2 years ago

@ElshiatyTube Thank you my friend for your feedback.

Mounir-Bouaiche commented 2 years ago

Hi @ElshiatyTube , I have recently published the new version of the library. Go check it out and if it works fine for you please close this issue, or else drop error log here. Thank you.

ElshiatyTube commented 2 years ago

@Mounir-Bouaiche v 5.5.1 works as expected, Thanks