Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/Enhancement] Does not take the MediaQueryData of the parent #572

Open
Blyynd opened this issue Jun 19, 2024 · 0 comments
Open

[Feature/Enhancement] Does not take the MediaQueryData of the parent #572

Blyynd opened this issue Jun 19, 2024 · 0 comments

Comments

@Blyynd
Copy link

Blyynd commented Jun 19, 2024

I have a specific case where i was in need of in ensureScreenSize (for a web container where the size of the screen is not the all screen, to render an actual mobile experience on web). I saw that is it deprecated in release notes.

I have to fork your package to force a mediaQueryData (initializing mq in your code)

    const double designWidth = 396;
    const double designHeight = 852;

    printOnDebug("Is web : ${kIsWeb.toString()}");

    double width = designWidth;
    double height = MediaQuery.sizeOf(context).height;
    if(!kIsWeb) {
      width = MediaQuery.sizeOf(context).width;
    }

    final customSize = Size(width, height);
    MediaQueryData data = MediaQuery.of(context).copyWith(
        size: customSize
    );
    
    return MediaQuery(
        data: data,
        child : Builder(
            builder: (context) {
              return ScreenUtilInit(
                designSize: const Size(designWidth, designHeight),
                data: data,
                minTextAdapt: true,
                builder: (context, child) {
                
                ....

In your class

class ScreenUtilInit extends StatefulWidget {
  /// A helper widget that initializes [ScreenUtil]
  const ScreenUtilInit({
    Key? key,
    this.builder,
    this.child,
    this.rebuildFactor = RebuildFactors.size,
    this.data,
    this.designSize = ScreenUtil.defaultSize,
    this.splitScreenMode = false,
    this.minTextAdapt = false,
    this.useInheritedMediaQuery = false,
    this.ensureScreenSize = false,
    this.enableScaleWH,
    this.enableScaleText,
    this.responsiveWidgets,
    this.excludeWidgets,
    this.fontSizeResolver = FontSizeResolvers.width,
  }) : super(key: key);

  final ScreenUtilInitBuilder? builder;
  final Widget? child;
  final bool splitScreenMode;
  final bool minTextAdapt;
  final bool useInheritedMediaQuery;
  final bool ensureScreenSize;
  final MediaQueryData? data;
  final bool Function()? enableScaleWH;
  final bool Function()? enableScaleText;
  final RebuildFactor rebuildFactor;
  final FontSizeResolver fontSizeResolver;

  /// The [Size] of the device in the design draft, in dp
  final Size designSize;
  final Iterable<String>? responsiveWidgets;
  final Iterable<String>? excludeWidgets;

and passing to mq :

  @override
  Widget build(BuildContext context) {
    MediaQueryData? mq = _mediaQueryData;
    if(widget.data != null) mq = widget.data;

It would be nice to have that native in your package

@Blyynd Blyynd changed the title Does not take the MediaQueryData of the parent [Feature/Enhancement] Does not take the MediaQueryData of the parent Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant