Skip to content

Commit

Permalink
bugifx: useInheritedMediaQuery 为 false 时,键盘可能覆盖输入框 (#487)
Browse files Browse the repository at this point in the history
* bugifx: 某些情况下键盘无法弹起

* update readme
  • Loading branch information
naivetoby authored Jun 1, 2023
1 parent 8613ffe commit a27e646
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 60 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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!**
Expand Down Expand Up @@ -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 <br/><br/> ~~Set this to true for Flutter 3.10 to avoid keyboard overlay on TextField~~ |

**Note : You must either provide builder, child or both.**

Expand Down
7 changes: 4 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -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在不同尺寸的屏幕上都能显示合理的布局!**

Expand Down
7 changes: 4 additions & 3 deletions README_PT.md
Original file line number Diff line number Diff line change
@@ -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!**

Expand Down
2 changes: 1 addition & 1 deletion example/lib/src/first_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
77 changes: 39 additions & 38 deletions lib/src/screenutil_init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,13 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
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));
Expand Down Expand Up @@ -127,18 +121,21 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
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(
Expand All @@ -152,34 +149,38 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
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),
),
),
);
}
}

0 comments on commit a27e646

Please sign in to comment.