Simon
Committed by GitHub

Merge branch 'OpenFlutter:master' into main

1 -name: Close inactive issues 1 +# .github/workflows/publish.yml
  2 +name: Publish to pub.dev
  3 +
2 on: 4 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'
5 8
  9 +# Publish using custom workflow
6 jobs: 10 jobs:
7 - close-issues:  
8 - runs-on: ubuntu-latest 11 + publish:
9 permissions: 12 permissions:
10 - issues: write  
11 - pull-requests: write 13 + id-token: write # Required for authentication using OIDC
  14 + runs-on: ubuntu-latest
12 steps: 15 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
  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 +
1 # 5.9.0 10 # 5.9.0
2 - ScreenUtilInit won't rebuild the whole widget tree 11 - ScreenUtilInit won't rebuild the whole widget tree
3 - Add `fontSizeResolver` to specify how font size should be scaled 12 - Add `fontSizeResolver` to specify how font size should be scaled
@@ -40,17 +40,19 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -40,17 +40,19 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
40 40
41 ### Properties 41 ### Properties
42 42
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 +
54 56
55 **Note : You must either provide builder, child or both.** 57 **Note : You must either provide builder, child or both.**
56 58
@@ -361,3 +363,28 @@ To use second method run: `flutter run --dart-define=method=2` @@ -361,3 +363,28 @@ To use second method run: `flutter run --dart-define=method=2`
361 363
362 ![effect](demo_en.png) 364 ![effect](demo_en.png)
363 ![tablet effect](demo_tablet_en.png) 365 ![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 +```
@@ -39,7 +39,7 @@ android { @@ -39,7 +39,7 @@ android {
39 defaultConfig { 39 defaultConfig {
40 // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 40 // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
41 applicationId "li.zhuoyuan.example" 41 applicationId "li.zhuoyuan.example"
42 - minSdkVersion 16 42 + minSdkVersion flutter.minSdkVersion
43 targetSdkVersion 31 43 targetSdkVersion 31
44 versionCode flutterVersionCode.toInteger() 44 versionCode flutterVersionCode.toInteger()
45 versionName flutterVersionName 45 versionName flutterVersionName
@@ -3,12 +3,11 @@ @@ -3,12 +3,11 @@
3 export "FLUTTER_ROOT=/Users/lizhuoyuan/fvm/versions/stable" 3 export "FLUTTER_ROOT=/Users/lizhuoyuan/fvm/versions/stable"
4 export "FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example" 4 export "FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example"
5 export "COCOAPODS_PARALLEL_CODE_SIGN=true" 5 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"
7 export "FLUTTER_BUILD_DIR=build" 7 export "FLUTTER_BUILD_DIR=build"
8 export "FLUTTER_BUILD_NAME=1.0.0" 8 export "FLUTTER_BUILD_NAME=1.0.0"
9 export "FLUTTER_BUILD_NUMBER=1" 9 export "FLUTTER_BUILD_NUMBER=1"
10 -export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9jZGJlZGE3ODhhMjkzZmEyOTY2NWRjM2ZhM2Q2ZTYzYmQyMjFjYjBkLw=="  
11 export "DART_OBFUSCATION=false" 10 export "DART_OBFUSCATION=false"
12 export "TRACK_WIDGET_CREATION=true" 11 export "TRACK_WIDGET_CREATION=true"
13 export "TREE_SHAKE_ICONS=false" 12 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"
1 import 'package:example/responsive_widgets.su.dart'; 1 import 'package:example/responsive_widgets.su.dart';
2 -import 'package:example/src/home.dart';  
3 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
4 import 'package:flutter_screenutil/flutter_screenutil.dart'; 3 import 'package:flutter_screenutil/flutter_screenutil.dart';
5 4
  5 +import '../src_zh/home.dart';
  6 +
6 class MyApp extends StatelessWidget { 7 class MyApp extends StatelessWidget {
7 const MyApp({Key? key}) : super(key: key); 8 const MyApp({Key? key}) : super(key: key);
8 9
@@ -3,7 +3,8 @@ @@ -3,7 +3,8 @@
3 * email: zhuoyuan93@gmail.com 3 * email: zhuoyuan93@gmail.com
4 */ 4 */
5 5
6 -import 'dart:io'; 6 +import 'package:flutter/foundation.dart' show kIsWeb, defaultTargetPlatform;
  7 +
7 import 'dart:math' show min, max; 8 import 'dart:math' show min, max;
8 import 'dart:ui' as ui show FlutterView; 9 import 'dart:ui' as ui show FlutterView;
9 10
@@ -154,8 +155,9 @@ class ScreenUtil { @@ -154,8 +155,9 @@ class ScreenUtil {
154 bool minTextAdapt = false, 155 bool minTextAdapt = false,
155 FontSizeResolver? fontSizeResolver, 156 FontSizeResolver? fontSizeResolver,
156 }) { 157 }) {
  158 + final view = View.maybeOf(context);
157 return configure( 159 return configure(
158 - data: MediaQuery.maybeOf(context), 160 + data: view != null ? MediaQueryData.fromView(view) : null,
159 designSize: designSize, 161 designSize: designSize,
160 splitScreenMode: splitScreenMode, 162 splitScreenMode: splitScreenMode,
161 minTextAdapt: minTextAdapt, 163 minTextAdapt: minTextAdapt,
@@ -171,8 +173,8 @@ class ScreenUtil { @@ -171,8 +173,8 @@ class ScreenUtil {
171 FontSizeResolver? fontSizeResolver, 173 FontSizeResolver? fontSizeResolver,
172 }) { 174 }) {
173 return ScreenUtil.ensureScreenSize().then((_) { 175 return ScreenUtil.ensureScreenSize().then((_) {
174 - return configure(  
175 - data: MediaQuery.maybeOf(context), 176 + return init(
  177 + context,
176 designSize: designSize, 178 designSize: designSize,
177 minTextAdapt: minTextAdapt, 179 minTextAdapt: minTextAdapt,
178 splitScreenMode: splitScreenMode, 180 splitScreenMode: splitScreenMode,
@@ -255,34 +257,43 @@ class ScreenUtil { @@ -255,34 +257,43 @@ class ScreenUtil {
255 double setSp(num fontSize) => 257 double setSp(num fontSize) =>
256 fontSizeResolver?.call(fontSize, _instance) ?? fontSize * scaleText; 258 fontSizeResolver?.call(fontSize, _instance) ?? fontSize * scaleText;
257 259
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;
269 } 293 }
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 + }
285 } 295 }
  296 +
286 return deviceType; 297 return deviceType;
287 } 298 }
288 299
@@ -2,10 +2,10 @@ import 'dart:async'; @@ -2,10 +2,10 @@ import 'dart:async';
2 import 'dart:collection'; 2 import 'dart:collection';
3 3
4 import 'package:flutter/widgets.dart'; 4 import 'package:flutter/widgets.dart';
5 -import './_flutter_widgets.dart';  
6 5
7 -import 'screenutil_mixin.dart'; 6 +import './_flutter_widgets.dart';
8 import 'screen_util.dart'; 7 import 'screen_util.dart';
  8 +import 'screenutil_mixin.dart';
9 9
10 typedef RebuildFactor = bool Function(MediaQueryData old, MediaQueryData data); 10 typedef RebuildFactor = bool Function(MediaQueryData old, MediaQueryData data);
11 11
@@ -75,6 +75,7 @@ class ScreenUtilInit extends StatefulWidget { @@ -75,6 +75,7 @@ class ScreenUtilInit extends StatefulWidget {
75 this.useInheritedMediaQuery = false, 75 this.useInheritedMediaQuery = false,
76 this.ensureScreenSize = false, 76 this.ensureScreenSize = false,
77 this.responsiveWidgets, 77 this.responsiveWidgets,
  78 + this.excludeWidgets,
78 this.fontSizeResolver = FontSizeResolvers.width, 79 this.fontSizeResolver = FontSizeResolvers.width,
79 }) : super(key: key); 80 }) : super(key: key);
80 81
@@ -90,6 +91,7 @@ class ScreenUtilInit extends StatefulWidget { @@ -90,6 +91,7 @@ class ScreenUtilInit extends StatefulWidget {
90 /// The [Size] of the device in the design draft, in dp 91 /// The [Size] of the device in the design draft, in dp
91 final Size designSize; 92 final Size designSize;
92 final Iterable<String>? responsiveWidgets; 93 final Iterable<String>? responsiveWidgets;
  94 + final Iterable<String>? excludeWidgets;
93 95
94 @override 96 @override
95 State<ScreenUtilInit> createState() => _ScreenUtilInitState(); 97 State<ScreenUtilInit> createState() => _ScreenUtilInitState();
@@ -98,6 +100,7 @@ class ScreenUtilInit extends StatefulWidget { @@ -98,6 +100,7 @@ class ScreenUtilInit extends StatefulWidget {
98 class _ScreenUtilInitState extends State<ScreenUtilInit> 100 class _ScreenUtilInitState extends State<ScreenUtilInit>
99 with WidgetsBindingObserver { 101 with WidgetsBindingObserver {
100 final _canMarkedToBuild = HashSet<String>(); 102 final _canMarkedToBuild = HashSet<String>();
  103 + final _excludedWidgets = HashSet<String>();
101 MediaQueryData? _mediaQueryData; 104 MediaQueryData? _mediaQueryData;
102 final _binding = WidgetsBinding.instance; 105 final _binding = WidgetsBinding.instance;
103 final _screenSizeCompleter = Completer<void>(); 106 final _screenSizeCompleter = Completer<void>();
@@ -126,10 +129,9 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> @@ -126,10 +129,9 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
126 } 129 }
127 130
128 MediaQueryData? _newData() { 131 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;
133 } 135 }
134 136
135 Future<void> _validateSize() async { 137 Future<void> _validateSize() async {
@@ -138,6 +140,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit> @@ -138,6 +140,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
138 140
139 void _markNeedsBuildIfAllowed(Element el) { 141 void _markNeedsBuildIfAllowed(Element el) {
140 final widgetName = el.widget.runtimeType.toString(); 142 final widgetName = el.widget.runtimeType.toString();
  143 + if (_excludedWidgets.contains(widgetName)) return;
141 final allowed = widget is SU || 144 final allowed = widget is SU ||
142 _canMarkedToBuild.contains(widgetName) || 145 _canMarkedToBuild.contains(widgetName) ||
143 !(widgetName.startsWith('_') || flutterWidgets.contains(widgetName)); 146 !(widgetName.startsWith('_') || flutterWidgets.contains(widgetName));
@@ -114,7 +114,7 @@ extension EdgeInsetsExtension on EdgeInsets { @@ -114,7 +114,7 @@ extension EdgeInsetsExtension on EdgeInsets {
114 ); 114 );
115 } 115 }
116 116
117 -extension BorderRaduisExtension on BorderRadius { 117 +extension BorderRadiusExtension on BorderRadius {
118 /// Creates adapt BorderRadius using r [SizeExtension]. 118 /// Creates adapt BorderRadius using r [SizeExtension].
119 BorderRadius get r => copyWith( 119 BorderRadius get r => copyWith(
120 bottomLeft: bottomLeft.r, 120 bottomLeft: bottomLeft.r,
@@ -138,7 +138,7 @@ extension BorderRaduisExtension on BorderRadius { @@ -138,7 +138,7 @@ extension BorderRaduisExtension on BorderRadius {
138 ); 138 );
139 } 139 }
140 140
141 -extension RaduisExtension on Radius { 141 +extension RadiusExtension on Radius {
142 /// Creates adapt Radius using r [SizeExtension]. 142 /// Creates adapt Radius using r [SizeExtension].
143 Radius get r => Radius.elliptical(x.r, y.r); 143 Radius get r => Radius.elliptical(x.r, y.r);
144 144
1 name: flutter_screenutil 1 name: flutter_screenutil
2 description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models 2 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
4 homepage: https://github.com/OpenFlutter/flutter_screenutil 4 homepage: https://github.com/OpenFlutter/flutter_screenutil
5 5
6 environment: 6 environment: