Simon
Committed by GitHub

Merge branch 'OpenFlutter:master' into main

name: Close inactive issues
# .github/workflows/publish.yml
name: Publish to pub.dev
on:
schedule:
- cron: "30 1 * * *"
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*' # tag pattern on pub.dev: 'v'
# Publish using custom workflow
jobs:
close-issues:
runs-on: ubuntu-latest
publish:
permissions:
issues: write
pull-requests: write
id-token: write # Required for authentication using OIDC
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart pub get
# Here you can insert custom steps you need
# - run: dart tool/generate-code.dart
- name: Publish
run: dart pub publish --force
\ No newline at end of file
... ...
# 5.9.2
- Add ability to exclude widgets from from rebuild list
- Depend on View instead of MediaQuery
- update readme
# 5.9.1
- merge pr #550 #555 #556
- update readme
# 5.9.0
- ScreenUtilInit won't rebuild the whole widget tree
- Add `fontSizeResolver` to specify how font size should be scaled
... ...
... ... @@ -40,17 +40,19 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
### Properties
| Property | Type | Default Value | Description |
| ---------------- |--------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| 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* | Function that take old and new screen metrics and returns whether to rebuild or not when changes. |
| 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) |
| fontSizeResolver | Function | *default* | Function that specify how font size should be adapted. Default is that font size scale with width of screen. |
| 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)) |
| Property | Type | Default Value | Description |
| ----------------- | ---------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| 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_ | Function that take old and new screen metrics and returns whether to rebuild or not when changes. |
| 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) |
| fontSizeResolver | Function | _default_ | Function that specify how font size should be adapted. Default is that font size scale with width of screen. |
| 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)) |
| excludeWidgets | Iterable<String> | null | List/Set of widget names that should be excluded from rebuilding tree. |
**Note : You must either provide builder, child or both.**
... ... @@ -361,3 +363,28 @@ To use second method run: `flutter run --dart-define=method=2`
![effect](demo_en.png)
![tablet effect](demo_tablet_en.png)
### Update for Version 5.9.0 (Tests)
Reported as bug in [#515](https://github.com/OpenFlutter/flutter_screenutil/issues/515)
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.
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
Example usage:
```dart
testWidgets('Should ensure widgets settle correctly', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: ScreenUtilInit(
child: MyApp(),
),
),
);
// Insertion of recommended method to prevent failures
await tester.pumpAndSettle();
// Continue with your assertions and tests
});
```
\ No newline at end of file
... ...
... ... @@ -39,7 +39,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "li.zhuoyuan.example"
minSdkVersion 16
minSdkVersion flutter.minSdkVersion
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
... ...
... ... @@ -3,12 +3,11 @@
export "FLUTTER_ROOT=/Users/lizhuoyuan/fvm/versions/stable"
export "FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example/lib/main.dart"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9jZGJlZGE3ODhhMjkzZmEyOTY2NWRjM2ZhM2Q2ZTYzYmQyMjFjYjBkLw=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example/.dart_tool/package_config.json"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
... ...
import 'package:example/responsive_widgets.su.dart';
import 'package:example/src/home.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../src_zh/home.dart';
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
... ...
... ... @@ -3,7 +3,8 @@
* email: zhuoyuan93@gmail.com
*/
import 'dart:io';
import 'package:flutter/foundation.dart' show kIsWeb, defaultTargetPlatform;
import 'dart:math' show min, max;
import 'dart:ui' as ui show FlutterView;
... ... @@ -154,8 +155,9 @@ class ScreenUtil {
bool minTextAdapt = false,
FontSizeResolver? fontSizeResolver,
}) {
final view = View.maybeOf(context);
return configure(
data: MediaQuery.maybeOf(context),
data: view != null ? MediaQueryData.fromView(view) : null,
designSize: designSize,
splitScreenMode: splitScreenMode,
minTextAdapt: minTextAdapt,
... ... @@ -171,8 +173,8 @@ class ScreenUtil {
FontSizeResolver? fontSizeResolver,
}) {
return ScreenUtil.ensureScreenSize().then((_) {
return configure(
data: MediaQuery.maybeOf(context),
return init(
context,
designSize: designSize,
minTextAdapt: minTextAdapt,
splitScreenMode: splitScreenMode,
... ... @@ -255,34 +257,43 @@ class ScreenUtil {
double setSp(num fontSize) =>
fontSizeResolver?.call(fontSize, _instance) ?? fontSize * scaleText;
DeviceType deviceType() {
DeviceType deviceType;
switch (Platform.operatingSystem) {
case 'android':
case 'ios':
deviceType = DeviceType.mobile;
if ((orientation == Orientation.portrait && screenWidth < 600) ||
(orientation == Orientation.landscape && screenHeight < 600)) {
deviceType = DeviceType.mobile;
} else {
deviceType = DeviceType.tablet;
DeviceType deviceType(BuildContext context) {
var deviceType = DeviceType.web;
final screenWidth = MediaQuery.of(context).size.width;
final screenHeight = MediaQuery.of(context).size.height;
final orientation = MediaQuery.of(context).orientation;
if (kIsWeb) {
deviceType = DeviceType.web;
} else {
bool isMobile = defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.android;
bool isTablet =
(orientation == Orientation.portrait && screenWidth >= 600) ||
(orientation == Orientation.landscape && screenHeight >= 600);
if (isMobile) {
deviceType = isTablet ? DeviceType.tablet : DeviceType.mobile;
} else {
switch (defaultTargetPlatform) {
case TargetPlatform.linux:
deviceType = DeviceType.linux;
break;
case TargetPlatform.macOS:
deviceType = DeviceType.mac;
break;
case TargetPlatform.windows:
deviceType = DeviceType.windows;
break;
case TargetPlatform.fuchsia:
deviceType = DeviceType.fuchsia;
break;
default:
break;
}
break;
case 'linux':
deviceType = DeviceType.linux;
break;
case 'macos':
deviceType = DeviceType.mac;
break;
case 'windows':
deviceType = DeviceType.windows;
break;
case 'fuchsia':
deviceType = DeviceType.fuchsia;
break;
default:
deviceType = DeviceType.web;
}
}
return deviceType;
}
... ...
... ... @@ -2,10 +2,10 @@ import 'dart:async';
import 'dart:collection';
import 'package:flutter/widgets.dart';
import './_flutter_widgets.dart';
import 'screenutil_mixin.dart';
import './_flutter_widgets.dart';
import 'screen_util.dart';
import 'screenutil_mixin.dart';
typedef RebuildFactor = bool Function(MediaQueryData old, MediaQueryData data);
... ... @@ -75,6 +75,7 @@ class ScreenUtilInit extends StatefulWidget {
this.useInheritedMediaQuery = false,
this.ensureScreenSize = false,
this.responsiveWidgets,
this.excludeWidgets,
this.fontSizeResolver = FontSizeResolvers.width,
}) : super(key: key);
... ... @@ -90,6 +91,7 @@ class ScreenUtilInit extends StatefulWidget {
/// The [Size] of the device in the design draft, in dp
final Size designSize;
final Iterable<String>? responsiveWidgets;
final Iterable<String>? excludeWidgets;
@override
State<ScreenUtilInit> createState() => _ScreenUtilInitState();
... ... @@ -98,6 +100,7 @@ class ScreenUtilInit extends StatefulWidget {
class _ScreenUtilInitState extends State<ScreenUtilInit>
with WidgetsBindingObserver {
final _canMarkedToBuild = HashSet<String>();
final _excludedWidgets = HashSet<String>();
MediaQueryData? _mediaQueryData;
final _binding = WidgetsBinding.instance;
final _screenSizeCompleter = Completer<void>();
... ... @@ -126,10 +129,9 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
}
MediaQueryData? _newData() {
MediaQueryData? mq = MediaQuery.maybeOf(context);
if (mq == null) mq = MediaQueryData.fromView(View.of(context));
return mq;
final view = View.maybeOf(context);
if (view != null) return MediaQueryData.fromView(view);
return null;
}
Future<void> _validateSize() async {
... ... @@ -138,6 +140,7 @@ class _ScreenUtilInitState extends State<ScreenUtilInit>
void _markNeedsBuildIfAllowed(Element el) {
final widgetName = el.widget.runtimeType.toString();
if (_excludedWidgets.contains(widgetName)) return;
final allowed = widget is SU ||
_canMarkedToBuild.contains(widgetName) ||
!(widgetName.startsWith('_') || flutterWidgets.contains(widgetName));
... ...
... ... @@ -114,7 +114,7 @@ extension EdgeInsetsExtension on EdgeInsets {
);
}
extension BorderRaduisExtension on BorderRadius {
extension BorderRadiusExtension on BorderRadius {
/// Creates adapt BorderRadius using r [SizeExtension].
BorderRadius get r => copyWith(
bottomLeft: bottomLeft.r,
... ... @@ -138,7 +138,7 @@ extension BorderRaduisExtension on BorderRadius {
);
}
extension RaduisExtension on Radius {
extension RadiusExtension on Radius {
/// Creates adapt Radius using r [SizeExtension].
Radius get r => Radius.elliptical(x.r, y.r);
... ...
name: flutter_screenutil
description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
version: 5.9.0
version: 5.9.2
homepage: https://github.com/OpenFlutter/flutter_screenutil
environment:
... ...