diff --git a/README.md b/README.md
index 07bae22..f3255cf 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
# flutter_screenutil
-[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dev/packages/flutter_screenutil)
-[![pub points](https://badges.bar/flutter_screenutil/pub%20points)](https://pub.dev/packages/flutter_screenutil/score)
-[![popularity](https://badges.bar/flutter_screenutil/popularity)](https://pub.dev/packages/flutter_screenutil/score)
+[![Flutter Package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dev/packages/flutter_screenutil)
+[![Pub Points](https://img.shields.io/pub/points/flutter_screenutil)](https://pub.dev/packages/flutter_screenutil/score)
+[![Popularity](https://img.shields.io/pub/popularity/flutter_screenutil)](https://pub.dev/packages/flutter_screenutil/score)
[![CodeFactor](https://www.codefactor.io/repository/github/openflutter/flutter_screenutil/badge)](https://www.codefactor.io/repository/github/openflutter/flutter_screenutil)
**A flutter plugin for adapting screen and font size.Let your UI display a reasonable layout on different screen sizes!**
@@ -40,18 +40,18 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
### Property
-| Property | Type | Default Value | Description |
-| --------------- |--------------|---------------|-----------------------------------------------------------------------------|
-| deviceSize | Size | null | The size of the physical device |
-| designSize | Size | Size(360,690) | The size of the device screen in the design draft, in dp |
-| builder | Function | null | Return widget that uses the library in a property (ex: MaterialApp's theme) |
-| child | Widget | null | A part of builder that its dependencies/properties don't use the library |
-| rebuildFactor | Function | *default* | Returns whether to rebuild or not when screen metrics changes. |
-| orientation | Orientation | portrait | screen orientation |
-| splitScreenMode | bool | false | support for split screen |
-| minTextAdapt | bool | false | Whether to adapt the text according to the minimum of width and height |
-| context | BuildContext | null | Get physical device data if not provided, by MediaQuery.of(context) |
-| useInheritedMediaQuery | bool | true | Set this to true for Flutter 3.10 to avoid keyboard overlay on TextField |
+| Property | Type | Default Value | Description |
+| --------------- |--------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
+| deviceSize | Size | null | The size of the physical device |
+| designSize | Size | Size(360,690) | The size of the device screen in the design draft, in dp |
+| builder | Function | null | Return widget that uses the library in a property (ex: MaterialApp's theme) |
+| child | Widget | null | A part of builder that its dependencies/properties don't use the library |
+| rebuildFactor | Function | *default* | Returns whether to rebuild or not when screen metrics changes. |
+| orientation | Orientation | portrait | screen orientation |
+| splitScreenMode | bool | false | support for split screen |
+| minTextAdapt | bool | false | Whether to adapt the text according to the minimum of width and height |
+| context | BuildContext | null | Get physical device data if not provided, by MediaQuery.of(context) |
+| useInheritedMediaQuery | bool | false | Recommended use `false` avoid rebuild very frequently
~~Set this to true for Flutter 3.10 to avoid keyboard overlay on TextField~~ |
**Note : You must either provide builder, child or both.**
diff --git a/README_CN.md b/README_CN.md
index 23b49b7..7c5de32 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -1,8 +1,9 @@
# flutter_screenutil
-[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
-[![pub points](https://badges.bar/flutter_screenutil/pub%20points)](https://pub.dev/packages/flutter_screenutil/score)
-[![popularity](https://badges.bar/flutter_screenutil/popularity)](https://pub.dev/packages/flutter_screenutil/score)
+[![Flutter Package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dev/packages/flutter_screenutil)
+[![Pub Points](https://img.shields.io/pub/points/flutter_screenutil)](https://pub.dev/packages/flutter_screenutil/score)
+[![Popularity](https://img.shields.io/pub/popularity/flutter_screenutil)](https://pub.dev/packages/flutter_screenutil/score)
+[![CodeFactor](https://www.codefactor.io/repository/github/openflutter/flutter_screenutil/badge)](https://www.codefactor.io/repository/github/openflutter/flutter_screenutil)
**flutter 屏幕适配方案,用于调整屏幕和字体大小的flutter插件,让你的UI在不同尺寸的屏幕上都能显示合理的布局!**
diff --git a/README_PT.md b/README_PT.md
index 2110b56..458b635 100644
--- a/README_PT.md
+++ b/README_PT.md
@@ -1,8 +1,9 @@
# I don’t speak Portuguese, and other developers have translated the first version. I later modified it based on the translation software. It is recommended to read the English/Chinese version.
# flutter_screenutil
-[![pub package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dartlang.org/packages/flutter_screenutil)
-[![pub points](https://badges.bar/flutter_screenutil/pub%20points)](https://pub.dev/packages/flutter_screenutil/score)
-[![popularity](https://badges.bar/flutter_screenutil/popularity)](https://pub.dev/packages/flutter_screenutil/score)
+[![Flutter Package](https://img.shields.io/pub/v/flutter_screenutil.svg)](https://pub.dev/packages/flutter_screenutil)
+[![Pub Points](https://img.shields.io/pub/points/flutter_screenutil)](https://pub.dev/packages/flutter_screenutil/score)
+[![Popularity](https://img.shields.io/pub/popularity/flutter_screenutil)](https://pub.dev/packages/flutter_screenutil/score)
+[![CodeFactor](https://www.codefactor.io/repository/github/openflutter/flutter_screenutil/badge)](https://www.codefactor.io/repository/github/openflutter/flutter_screenutil)
**Um plugin Flutter para adaptação de tamanho de tela e fontes. Deixe sua UI exibir um layout aceitável em diferentes tamanhos de tela!**
diff --git a/example/lib/src/first_method.dart b/example/lib/src/first_method.dart
index bfe0b84..d61a977 100644
--- a/example/lib/src/first_method.dart
+++ b/example/lib/src/first_method.dart
@@ -9,7 +9,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
// In first method you only need to wrap [MaterialApp] with [ScreenUtilInit] and that's it
return ScreenUtilInit(
- useInheritedMediaQuery: true,
+ useInheritedMediaQuery: false,
builder: (_, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
diff --git a/lib/src/screenutil_init.dart b/lib/src/screenutil_init.dart
index 9d69f0d..f78fa2e 100644
--- a/lib/src/screenutil_init.dart
+++ b/lib/src/screenutil_init.dart
@@ -69,19 +69,13 @@ class _ScreenUtilInitState extends State
MediaQueryData get mediaQueryData => _mediaQueryData!;
MediaQueryData get newData {
- if (widget.useInheritedMediaQuery) {
- final data = MediaQuery.maybeOf(context);
+ final data = MediaQuery.maybeOf(context);
- if (data != null) {
+ if (data != null) {
+ if (widget.useInheritedMediaQuery) {
wrappedInMediaQuery = true;
- return data;
- }
- } else {
- final data = MediaQuery.maybeOf(context);
-
- if (data != null) {
- return data;
}
+ return data;
}
return MediaQueryData.fromView(View.of(context));
@@ -127,18 +121,21 @@ class _ScreenUtilInitState extends State
if (mediaQueryData.size == Size.zero) return const SizedBox.shrink();
if (!wrappedInMediaQuery) {
return MediaQuery(
- // key: GlobalObjectKey('mediaQuery'),
data: mediaQueryData,
child: Builder(
builder: (__context) {
+ ScreenUtil.init(
+ __context,
+ designSize: widget.designSize,
+ splitScreenMode: widget.splitScreenMode,
+ minTextAdapt: widget.minTextAdapt,
+ scaleByHeight: widget.scaleByHeight,
+ );
final deviceData = MediaQuery.maybeOf(__context);
final deviceSize = deviceData?.size ?? widget.designSize;
- ScreenUtil.init(__context,
- designSize: widget.designSize,
- splitScreenMode: widget.splitScreenMode,
- minTextAdapt: widget.minTextAdapt,
- scaleByHeight: widget.scaleByHeight);
- return Container(
+ return MediaQuery(
+ data: MediaQueryData.fromView(View.of(__context)),
+ child: Container(
width: deviceSize.width,
height: deviceSize.height,
child: FittedBox(
@@ -152,34 +149,38 @@ class _ScreenUtilInitState extends State
height: deviceSize.height,
child: widget.builder(__context, widget.child),
),
- ));
+ ),
+ ),
+ );
},
),
);
}
- ScreenUtil.init(_context,
- designSize: widget.designSize,
- splitScreenMode: widget.splitScreenMode,
- minTextAdapt: widget.minTextAdapt,
- scaleByHeight: widget.scaleByHeight);
+ ScreenUtil.init(
+ _context,
+ designSize: widget.designSize,
+ splitScreenMode: widget.splitScreenMode,
+ minTextAdapt: widget.minTextAdapt,
+ scaleByHeight: widget.scaleByHeight,
+ );
final deviceData = MediaQuery.maybeOf(_context);
-
final deviceSize = deviceData?.size ?? widget.designSize;
return Container(
- width: deviceSize.width,
- height: deviceSize.height,
- child: FittedBox(
- fit: BoxFit.none,
- alignment: Alignment.center,
- child: Container(
- width: widget.scaleByHeight
- ? (deviceSize.height * widget.designSize.width) /
- widget.designSize.height
- : deviceSize.width,
- height: deviceSize.height,
- child: widget.builder(_context, widget.child),
- ),
- ));
+ width: deviceSize.width,
+ height: deviceSize.height,
+ child: FittedBox(
+ fit: BoxFit.none,
+ alignment: Alignment.center,
+ child: Container(
+ width: widget.scaleByHeight
+ ? (deviceSize.height * widget.designSize.width) /
+ widget.designSize.height
+ : deviceSize.width,
+ height: deviceSize.height,
+ child: widget.builder(_context, widget.child),
+ ),
+ ),
+ );
}
}