Skip to content

Commit 05c823c

Browse files
Mounir-BouaicheMounir Bouaiche
and
Mounir Bouaiche
authored
Major updates & fixes (#491)
* Clean codes & add features & fix bugs Features/Bugs: - Feature: You can select what classes needs to be rebuilt instead of rebuilding everything, if you have widget A, either addi SU mixin or add 'A' to list ScreenUtilInit.responsiveWidgets - Feature: Using ScreenUtilInit.builder is optional (use it only when using library in theme) - Bug: Second call to ScreenUtil.init ignores any existing values and uses the default values when not provided, use ScreenUtil.configure instead - Bug: ScreenUtil.ensureScreenSize raises an overflow error * Update version * Add List of flutter widgets * Update logic if allowing widget to being rebuilt * Little code solidity * Add scale factors: diagonal & diameter * Add option for how font size should be scaled * Update support to Dart >= 2.17.0 * Add fontSizeResolver to init + helpers * Add ensureScreenSize to ScreenUtilInit constructor * Fix ensureScreenSize on web * Update Runner.rc * Add some methods to extensions * Update widget_test * Remove extra deps * Clean code * Add ensureScreenSizeAndInit + make init sync * Update README.md * Update CHANGELOG.md * Update version to 5.9.0 * Rename version * Adding tests * Changing version in CHANGELOG.md --------- Co-authored-by: Mounir Bouaiche <[email protected]>
1 parent de2df4f commit 05c823c

19 files changed

+1363
-227
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,6 @@ doc
139139
.lock
140140
coverage*
141141
*.lock
142+
143+
# Don't commit .fvm directory containing machine-specific symlink to sdk & flutter version
144+
**/.fvm

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 5.9.0-beta
2+
- ScreenUtilInit won't rebuild the whole widget tree
3+
- Add `fontSizeResolver` to specify how font size should be scaled
4+
- Add `diameter` & `diagonal` factors
5+
- `useInheritedMediaQuery` has not effect, and will be removed in next release
6+
- Fix `ensureScreenSize` in web platform
7+
18
# 5.8.4
29
- bug fix
310
- change useInheritedMediaQuery default value to false

README.md

+27-16
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,36 @@ dependencies:
3838
import 'package:flutter_screenutil/flutter_screenutil.dart';
3939
```
4040

41-
### Property
42-
43-
| Property | Type | Default Value | Description |
44-
| --------------- |--------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
45-
| deviceSize | Size | null | The size of the physical device |
46-
| designSize | Size | Size(360,690) | The size of the device screen in the design draft, in dp |
47-
| builder | Function | null | Return widget that uses the library in a property (ex: MaterialApp's theme) |
48-
| child | Widget | null | A part of builder that its dependencies/properties don't use the library |
49-
| rebuildFactor | Function | *default* | Returns whether to rebuild or not when screen metrics changes. |
50-
| orientation | Orientation | portrait | screen orientation |
51-
| splitScreenMode | bool | false | support for split screen |
52-
| minTextAdapt | bool | false | Whether to adapt the text according to the minimum of width and height |
53-
| context | BuildContext | null | Get physical device data if not provided, by MediaQuery.of(context) |
54-
| 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~~ |
41+
### Properties
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+
| reponsiveWidgets | 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)) |
5554

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

57+
### Rebuild list
58+
Starting from version 5.9.0, ScreenUtilInit won't rebuild the whole widget tree, instead it will mark widget needs build only if:
59+
- Widget is not a flutter widget (widgets are available in [Flutter Docs](https://docs.flutter.dev/reference/widgets))
60+
- Widget does not start with underscore (`_`)
61+
- Widget does not declare `SU` mixin
62+
- `reponsiveWidgets` does not contains widget name
63+
64+
If you have a widget that uses the library and doesn't meet these options you can either add `SU` mixin or add widget name in responsiveWidgets list.
65+
5866
### Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option
5967

6068
Please set the size of the design draft before use, the width and height of the design draft.
6169

62-
#### The first way (You must use it once in your app)
70+
#### The first way (You should use it once in your app)
6371

6472
```dart
6573
void main() => runApp(MyApp());
@@ -74,7 +82,8 @@ class MyApp extends StatelessWidget {
7482
designSize: const Size(360, 690),
7583
minTextAdapt: true,
7684
splitScreenMode: true,
77-
builder: (context , child) {
85+
// Use builder only if you need to use library outside ScreenUtilInit context
86+
builder: (_ , child) {
7887
return MaterialApp(
7988
debugShowCheckedModeBanner: false,
8089
title: 'First Method',
@@ -169,6 +178,8 @@ class _HomePageState extends State<HomePage> {
169178
}
170179
```
171180

181+
**Note: calling ScreenUtil.init second time, any non-provided parameter will not be replaced with default value. Use ScreenUtil.configure instead**
182+
172183
### API
173184

174185
#### Pass the dp size of the design draft

example/lib/responsive_widgets.g.dart

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/////////////////////////////////////////////////////////////////////////
2+
/// Generated via plugin: flutter_screenutil_generator - Do Not Touch ///
3+
/////////////////////////////////////////////////////////////////////////
4+
5+
part of 'responsive_widgets.su.dart';
6+
7+
const _responsiveWidgets = {
8+
'MyThemedApp',
9+
'MyApp',
10+
'HomePageScaffold',
11+
};
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
part 'responsive_widgets.g.dart';
2+
3+
get responsiveWidgets => _responsiveWidgets;

example/lib/src/first_method.dart

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:example/responsive_widgets.su.dart';
12
import 'package:example/src/home.dart';
23
import 'package:flutter/material.dart';
34
import 'package:flutter_screenutil/flutter_screenutil.dart';
@@ -9,22 +10,20 @@ class MyApp extends StatelessWidget {
910
Widget build(BuildContext context) {
1011
// In first method you only need to wrap [MaterialApp] with [ScreenUtilInit] and that's it
1112
return ScreenUtilInit(
12-
useInheritedMediaQuery: false,
13-
builder: (_, child) {
14-
return MaterialApp(
15-
debugShowCheckedModeBanner: false,
16-
title: 'First Method',
17-
// You can use the library anywhere in the app even in theme
18-
theme: ThemeData(
19-
primarySwatch: Colors.blue,
20-
textTheme: Typography(platform: TargetPlatform.iOS)
21-
.black
22-
.apply(fontSizeFactor: 1),
23-
),
24-
home: child,
25-
);
26-
},
27-
child: const HomePage(title: 'First Method'),
13+
responsiveWidgets: responsiveWidgets,
14+
ensureScreenSize: true,
15+
child: MaterialApp(
16+
debugShowCheckedModeBanner: false,
17+
title: 'First Method',
18+
// You can use the library anywhere in the app even in theme
19+
theme: ThemeData(
20+
primarySwatch: Colors.blue,
21+
textTheme: Typography(platform: TargetPlatform.iOS)
22+
.black
23+
.apply(fontSizeFactor: 1),
24+
),
25+
home: const HomePage(title: 'First Method'),
26+
),
2827
);
2928
}
3029
}

example/lib/src/home.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
33
import 'package:flutter_screenutil/flutter_screenutil.dart';
44

5-
class HomePageScaffold extends StatelessWidget {
5+
class HomePageScaffold extends StatelessWidget with SU {
66
const HomePageScaffold({Key? key, this.title = ''}) : super(key: key);
77

88
void printScreenInformation(BuildContext context) {

example/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ dev_dependencies:
2727
test: ^1.15.7
2828

2929
flutter:
30-
uses-material-design: true
30+
uses-material-design: true

example/test/widget_test.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void main() {
4343
data: currentData,
4444
child: ScreenUtilInit(
4545
designSize: designSize,
46-
builder: (context, child) => MaterialApp(
46+
child: MaterialApp(
4747
home: Material(
4848
child: TextButton(
4949
key: _key,
@@ -68,6 +68,9 @@ void main() {
6868
// Tests with initial screen size
6969
testSize(initialSize);
7070

71+
// Wait for FutureBuilder to be resolved
72+
await tester.pumpAndSettle();
73+
7174
// Click On button to simulate changing screen size
7275
await tap();
7376
// Tests with bigger screen size

example/windows/runner/Runner.rc

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
6060
// Version
6161
//
6262

63-
#ifdef FLUTTER_BUILD_NUMBER
64-
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
63+
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
64+
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
6565
#else
66-
#define VERSION_AS_NUMBER 1,0,0
66+
#define VERSION_AS_NUMBER 1,0,0,0
6767
#endif
6868

69-
#ifdef FLUTTER_BUILD_NAME
70-
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
69+
#if defined(FLUTTER_VERSION)
70+
#define VERSION_AS_STRING FLUTTER_VERSION
7171
#else
7272
#define VERSION_AS_STRING "1.0.0"
7373
#endif

lib/flutter_screenutil.dart

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export 'src/r_sizedbox.dart';
1010
export 'src/screen_util.dart';
1111
export 'src/screenutil_init.dart';
1212
export 'src/size_extension.dart';
13+
export 'src/screenutil_mixin.dart';

0 commit comments

Comments
 (0)