Skip to content

Commit aec9c11

Browse files
authored
Merge branch 'OpenFlutter:master' into main
2 parents c31fffe + 1c355fc commit aec9c11

File tree

10 files changed

+123
-72
lines changed

10 files changed

+123
-72
lines changed

.github/workflows/actions.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
name: Close inactive issues
1+
# .github/workflows/publish.yml
2+
name: Publish to pub.dev
3+
24
on:
3-
schedule:
4-
- cron: "30 1 * * *"
5+
push:
6+
tags:
7+
- 'v[0-9]+.[0-9]+.[0-9]+*' # tag pattern on pub.dev: 'v'
58

9+
# Publish using custom workflow
610
jobs:
7-
close-issues:
8-
runs-on: ubuntu-latest
11+
publish:
912
permissions:
10-
issues: write
11-
pull-requests: write
13+
id-token: write # Required for authentication using OIDC
14+
runs-on: ubuntu-latest
1215
steps:
13-
- uses: actions/stale@v3
14-
with:
15-
days-before-issue-stale: 30
16-
days-before-issue-close: 14
17-
stale-issue-label: "stale"
18-
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
19-
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
20-
days-before-pr-stale: -1
21-
days-before-pr-close: -1
22-
repo-token: ${{ secrets.GITHUB_TOKEN }}
16+
- uses: actions/checkout@v3
17+
- uses: dart-lang/setup-dart@v1
18+
- name: Install dependencies
19+
run: dart pub get
20+
# Here you can insert custom steps you need
21+
# - run: dart tool/generate-code.dart
22+
- name: Publish
23+
run: dart pub publish --force

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 5.9.2
2+
- Add ability to exclude widgets from from rebuild list
3+
- Depend on View instead of MediaQuery
4+
- update readme
5+
6+
# 5.9.1
7+
- merge pr #550 #555 #556
8+
- update readme
9+
110
# 5.9.0
211
- ScreenUtilInit won't rebuild the whole widget tree
312
- Add `fontSizeResolver` to specify how font size should be scaled

README.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
4040

4141
### Properties
4242

43-
| Property | Type | Default Value | Description |
44-
| ---------------- |--------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
45-
| designSize | Size | Size(360,690) | The size of the device screen in the design draft, in dp |
46-
| builder | Function | null | Return widget that uses the library in a property (ex: MaterialApp's theme) |
47-
| child | Widget | null | A part of builder that its dependencies/properties don't use the library |
48-
| rebuildFactor | Function | *default* | Function that take old and new screen metrics and returns whether to rebuild or not when changes. |
49-
| splitScreenMode | bool | false | support for split screen |
50-
| minTextAdapt | bool | false | Whether to adapt the text according to the minimum of width and height |
51-
| context | BuildContext | null | Get physical device data if not provided, by MediaQuery.of(context) |
52-
| fontSizeResolver | Function | *default* | Function that specify how font size should be adapted. Default is that font size scale with width of screen. |
53-
| responsiveWidgets| Iterable<String> | null | List/Set of widget names that should be included in rebuilding tree. (See [How flutter_screenutil marks a widget needs build](#rebuild-list)) |
43+
| Property | Type | Default Value | Description |
44+
| ----------------- | ---------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
45+
| designSize | Size | Size(360,690) | The size of the device screen in the design draft, in dp |
46+
| builder | Function | null | Return widget that uses the library in a property (ex: MaterialApp's theme) |
47+
| child | Widget | null | A part of builder that its dependencies/properties don't use the library |
48+
| rebuildFactor | Function | _default_ | Function that take old and new screen metrics and returns whether to rebuild or not when changes. |
49+
| splitScreenMode | bool | false | support for split screen |
50+
| minTextAdapt | bool | false | Whether to adapt the text according to the minimum of width and height |
51+
| context | BuildContext | null | Get physical device data if not provided, by MediaQuery.of(context) |
52+
| fontSizeResolver | Function | _default_ | Function that specify how font size should be adapted. Default is that font size scale with width of screen. |
53+
| responsiveWidgets | Iterable<String> | null | List/Set of widget names that should be included in rebuilding tree. (See [How flutter_screenutil marks a widget needs build](#rebuild-list)) |
54+
| excludeWidgets | Iterable<String> | null | List/Set of widget names that should be excluded from rebuilding tree. |
55+
5456

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

@@ -361,3 +363,28 @@ To use second method run: `flutter run --dart-define=method=2`
361363

362364
![effect](demo_en.png)
363365
![tablet effect](demo_tablet_en.png)
366+
367+
368+
### Update for Version 5.9.0 (Tests)
369+
Reported as bug in [#515](https://github.com/OpenFlutter/flutter_screenutil/issues/515)
370+
371+
372+
In version 5.9.0, to ensure compatibility and proper functioning of your tests, it is crucial to use the method `tester.pumpAndSettle()`; when conducting widget tests that depend on animations or a settling time to complete their state.
373+
374+
In the previous version, this step was not strictly necessary. However, to maintain consistency in your tests and avoid unexpected errors, it's strongly recommended incorporating await tester.pumpAndSettle(); in your widget tests if you are using version 5.9.0
375+
376+
Example usage:
377+
```dart
378+
testWidgets('Should ensure widgets settle correctly', (WidgetTester tester) async {
379+
await tester.pumpWidget(
380+
const MaterialApp(
381+
home: ScreenUtilInit(
382+
child: MyApp(),
383+
),
384+
),
385+
);
386+
// Insertion of recommended method to prevent failures
387+
await tester.pumpAndSettle();
388+
// Continue with your assertions and tests
389+
});
390+
```

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ android {
3939
defaultConfig {
4040
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
4141
applicationId "li.zhuoyuan.example"
42-
minSdkVersion 16
42+
minSdkVersion flutter.minSdkVersion
4343
targetSdkVersion 31
4444
versionCode flutterVersionCode.toInteger()
4545
versionName flutterVersionName

example/ios/Flutter/flutter_export_environment.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
export "FLUTTER_ROOT=/Users/lizhuoyuan/fvm/versions/stable"
44
export "FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example"
55
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
6-
export "FLUTTER_TARGET=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example/lib/main.dart"
6+
export "FLUTTER_TARGET=lib/main.dart"
77
export "FLUTTER_BUILD_DIR=build"
88
export "FLUTTER_BUILD_NAME=1.0.0"
99
export "FLUTTER_BUILD_NUMBER=1"
10-
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9jZGJlZGE3ODhhMjkzZmEyOTY2NWRjM2ZhM2Q2ZTYzYmQyMjFjYjBkLw=="
1110
export "DART_OBFUSCATION=false"
1211
export "TRACK_WIDGET_CREATION=true"
1312
export "TREE_SHAKE_ICONS=false"
14-
export "PACKAGE_CONFIG=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example/.dart_tool/package_config.json"
13+
export "PACKAGE_CONFIG=.dart_tool/package_config.json"

example/lib/src/first_method.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'package:example/responsive_widgets.su.dart';
2-
import 'package:example/src/home.dart';
32
import 'package:flutter/material.dart';
43
import 'package:flutter_screenutil/flutter_screenutil.dart';
54

5+
import '../src_zh/home.dart';
6+
67
class MyApp extends StatelessWidget {
78
const MyApp({Key? key}) : super(key: key);
89

lib/src/screen_util.dart

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* email: zhuoyuan93@gmail.com
44
*/
55

6-
import 'dart:io';
6+
import 'package:flutter/foundation.dart' show kIsWeb, defaultTargetPlatform;
7+
78
import 'dart:math' show min, max;
89
import 'dart:ui' as ui show FlutterView;
910

@@ -154,8 +155,9 @@ class ScreenUtil {
154155
bool minTextAdapt = false,
155156
FontSizeResolver? fontSizeResolver,
156157
}) {
158+
final view = View.maybeOf(context);
157159
return configure(
158-
data: MediaQuery.maybeOf(context),
160+
data: view != null ? MediaQueryData.fromView(view) : null,
159161
designSize: designSize,
160162
splitScreenMode: splitScreenMode,
161163
minTextAdapt: minTextAdapt,
@@ -171,8 +173,8 @@ class ScreenUtil {
171173
FontSizeResolver? fontSizeResolver,
172174
}) {
173175
return ScreenUtil.ensureScreenSize().then((_) {
174-
return configure(
175-
data: MediaQuery.maybeOf(context),
176+
return init(
177+
context,
176178
designSize: designSize,
177179
minTextAdapt: minTextAdapt,
178180
splitScreenMode: splitScreenMode,
@@ -255,34 +257,43 @@ class ScreenUtil {
255257
double setSp(num fontSize) =>
256258
fontSizeResolver?.call(fontSize, _instance) ?? fontSize * scaleText;
257259

258-
DeviceType deviceType() {
259-
DeviceType deviceType;
260-
switch (Platform.operatingSystem) {
261-
case 'android':
262-
case 'ios':
263-
deviceType = DeviceType.mobile;
264-
if ((orientation == Orientation.portrait && screenWidth < 600) ||
265-
(orientation == Orientation.landscape && screenHeight < 600)) {
266-
deviceType = DeviceType.mobile;
267-
} else {
268-
deviceType = DeviceType.tablet;
260+
DeviceType deviceType(BuildContext context) {
261+
var deviceType = DeviceType.web;
262+
final screenWidth = MediaQuery.of(context).size.width;
263+
final screenHeight = MediaQuery.of(context).size.height;
264+
final orientation = MediaQuery.of(context).orientation;
265+
266+
if (kIsWeb) {
267+
deviceType = DeviceType.web;
268+
} else {
269+
bool isMobile = defaultTargetPlatform == TargetPlatform.iOS ||
270+
defaultTargetPlatform == TargetPlatform.android;
271+
bool isTablet =
272+
(orientation == Orientation.portrait && screenWidth >= 600) ||
273+
(orientation == Orientation.landscape && screenHeight >= 600);
274+
275+
if (isMobile) {
276+
deviceType = isTablet ? DeviceType.tablet : DeviceType.mobile;
277+
} else {
278+
switch (defaultTargetPlatform) {
279+
case TargetPlatform.linux:
280+
deviceType = DeviceType.linux;
281+
break;
282+
case TargetPlatform.macOS:
283+
deviceType = DeviceType.mac;
284+
break;
285+
case TargetPlatform.windows:
286+
deviceType = DeviceType.windows;
287+
break;
288+
case TargetPlatform.fuchsia:
289+
deviceType = DeviceType.fuchsia;
290+
break;
291+
default:
292+
break;
269293
}
270-
break;
271-
case 'linux':
272-
deviceType = DeviceType.linux;
273-
break;
274-
case 'macos':
275-
deviceType = DeviceType.mac;
276-
break;
277-
case 'windows':
278-
deviceType = DeviceType.windows;
279-
break;
280-
case 'fuchsia':
281-
deviceType = DeviceType.fuchsia;
282-
break;
283-
default:
284-
deviceType = DeviceType.web;
294+
}
285295
}
296+
286297
return deviceType;
287298
}
288299

lib/src/screenutil_init.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import 'dart:async';
22
import 'dart:collection';
33

44
import 'package:flutter/widgets.dart';
5-
import './_flutter_widgets.dart';
65

7-
import 'screenutil_mixin.dart';
6+
import './_flutter_widgets.dart';
87
import 'screen_util.dart';
8+
import 'screenutil_mixin.dart';
99

1010
typedef RebuildFactor = bool Function(MediaQueryData old, MediaQueryData data);
1111

@@ -75,6 +75,7 @@ class ScreenUtilInit extends StatefulWidget {
7575
this.useInheritedMediaQuery = false,
7676
this.ensureScreenSize = false,
7777
this.responsiveWidgets,
78+
this.excludeWidgets,
7879
this.fontSizeResolver = FontSizeResolvers.width,
7980
}) : super(key: key);
8081

@@ -90,6 +91,7 @@ class ScreenUtilInit extends StatefulWidget {
9091
/// The [Size] of the device in the design draft, in dp
9192
final Size designSize;
9293
final Iterable<String>? responsiveWidgets;
94+
final Iterable<String>? excludeWidgets;
9395

9496
@override
9597
State<ScreenUtilInit> createState() => _ScreenUtilInitState();
@@ -98,6 +100,7 @@ class ScreenUtilInit extends StatefulWidget {
98100
class _ScreenUtilInitState extends State<ScreenUtilInit>
99101
with WidgetsBindingObserver {
100102
final _canMarkedToBuild = HashSet<String>();
103+
final _excludedWidgets = HashSet<String>();
101104
MediaQueryData? _mediaQueryData;
102105
final _binding = WidgetsBinding.instance;
103106
final _screenSizeCompleter = Completer<void>();
@@ -126,10 +129,9 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
126129
}
127130

128131
MediaQueryData? _newData() {
129-
MediaQueryData? mq = MediaQuery.maybeOf(context);
130-
if (mq == null) mq = MediaQueryData.fromView(View.of(context));
131-
132-
return mq;
132+
final view = View.maybeOf(context);
133+
if (view != null) return MediaQueryData.fromView(view);
134+
return null;
133135
}
134136

135137
Future<void> _validateSize() async {
@@ -138,6 +140,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
138140

139141
void _markNeedsBuildIfAllowed(Element el) {
140142
final widgetName = el.widget.runtimeType.toString();
143+
if (_excludedWidgets.contains(widgetName)) return;
141144
final allowed = widget is SU ||
142145
_canMarkedToBuild.contains(widgetName) ||
143146
!(widgetName.startsWith('_') || flutterWidgets.contains(widgetName));

lib/src/size_extension.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extension EdgeInsetsExtension on EdgeInsets {
114114
);
115115
}
116116

117-
extension BorderRaduisExtension on BorderRadius {
117+
extension BorderRadiusExtension on BorderRadius {
118118
/// Creates adapt BorderRadius using r [SizeExtension].
119119
BorderRadius get r => copyWith(
120120
bottomLeft: bottomLeft.r,
@@ -138,7 +138,7 @@ extension BorderRaduisExtension on BorderRadius {
138138
);
139139
}
140140

141-
extension RaduisExtension on Radius {
141+
extension RadiusExtension on Radius {
142142
/// Creates adapt Radius using r [SizeExtension].
143143
Radius get r => Radius.elliptical(x.r, y.r);
144144

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_screenutil
22
description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
3-
version: 5.9.0
3+
version: 5.9.2
44
homepage: https://github.com/OpenFlutter/flutter_screenutil
55

66
environment:

0 commit comments

Comments
 (0)