Skip to content

Commit caa26e6

Browse files
author
李卓原
committed
null safety
1 parent 5144545 commit caa26e6

File tree

5 files changed

+22
-71
lines changed

5 files changed

+22
-71
lines changed

CHANGELOG.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
<!--
2-
* @Author: [email protected]
3-
* @Date: 2018-10-16 19:43:03
4-
* @LastEditors: [email protected]
5-
* @LastEditTime: 2020年6月20日 11:20:02
6-
* @Description: Update log
7-
-->
1+
# 5.0.0-nullsafety.0
2+
- Migrated flutter_screenutil to non-nullable
83

94
# 4.0.0-beta3
105
- Optimize the way of initialization

example/pubspec.yaml

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,14 @@ dependencies:
1616
flutter:
1717
sdk: flutter
1818

19-
# The following adds the Cupertino Icons font to your application.
20-
# Use with the CupertinoIcons class for iOS style icons.
21-
cupertino_icons: ^0.1.2
2219
flutter_screenutil:
23-
path: ../
20+
2421
dev_dependencies:
2522
flutter_test:
2623
sdk: flutter
24+
test: ^1.15.7
2725

26+
dependency_overrides:
27+
flutter_screenutil:
28+
path: ../
2829

29-
# For information on the generic Dart part of this file, see the
30-
# following page: https://www.dartlang.org/tools/pub/pubspec
31-
32-
# The following section is specific to Flutter.
33-
flutter:
34-
35-
# The following line ensures that the Material Icons font is
36-
# included with your application, so that you can use the icons in
37-
# the material Icons class.
38-
uses-material-design: true
39-
40-
# To add assets to your application, add an assets section, like this:
41-
# assets:
42-
# - images/a_dot_burr.jpeg
43-
# - images/a_dot_ham.jpeg
44-
45-
# An image asset can refer to one or more resolution-specific "variants", see
46-
# https://flutter.io/assets-and-images/#resolution-aware.
47-
48-
# For details regarding adding assets from package dependencies, see
49-
# https://flutter.io/assets-and-images/#from-packages
50-
51-
# To add custom fonts to your application, add a fonts section here,
52-
# in this "flutter" section. Each entry in this list should have a
53-
# "family" key with the font family name, and a "fonts" key with a
54-
# list giving the asset and other descriptors for the font. For
55-
# example:
56-
# fonts:
57-
# - family: Schyler
58-
# fonts:
59-
# - asset: fonts/Schyler-Regular.ttf
60-
# - asset: fonts/Schyler-Italic.ttf
61-
# style: italic
62-
# - family: Trajan Pro
63-
# fonts:
64-
# - asset: fonts/TrajanPro.ttf
65-
# - asset: fonts/TrajanPro_Bold.ttf
66-
# weight: 700
67-
#
68-
# For details regarding fonts from package dependencies,
69-
# see https://flutter.io/custom-fonts/#from-packages

lib/screenutil.dart

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,26 @@ import 'dart:ui' as ui;
88

99
class ScreenUtil {
1010
static const Size defaultSize = Size(1080, 1920);
11-
static ScreenUtil _instance;
11+
static late ScreenUtil _instance;
1212

1313
/// UI设计中手机尺寸 , px
1414
/// Size of the phone in UI Design , px
15-
Size uiSize;
15+
late Size uiSize;
1616

1717
/// 控制字体是否要根据系统的“字体大小”辅助选项来进行缩放。默认值为false。
1818
/// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false.
19-
bool allowFontScaling;
19+
late bool allowFontScaling;
2020

21-
static double _pixelRatio;
22-
static double _textScaleFactor;
23-
static double _screenWidth;
24-
static double _screenHeight;
25-
static double _statusBarHeight;
26-
static double _bottomBarHeight;
21+
static late double _pixelRatio;
22+
static late double _textScaleFactor;
23+
static late double _screenWidth;
24+
static late double _screenHeight;
25+
static late double _statusBarHeight;
26+
static late double _bottomBarHeight;
2727

2828
ScreenUtil._();
2929

3030
factory ScreenUtil() {
31-
assert(
32-
_instance != null,
33-
'\nEnsure to initialize ScreenUtil before accessing it.\nPlease execute the init method : ScreenUtil.init()',
34-
);
3531
return _instance;
3632
}
3733

@@ -40,7 +36,7 @@ class ScreenUtil {
4036
Size designSize = defaultSize,
4137
bool allowFontScaling = false,
4238
}) {
43-
_instance ??= ScreenUtil._();
39+
_instance = ScreenUtil._();
4440
_instance
4541
..uiSize = designSize
4642
..allowFontScaling = allowFontScaling;
@@ -116,7 +112,7 @@ class ScreenUtil {
116112
///Font size adaptation method
117113
///- [fontSize] The size of the font on the UI design, in px.
118114
///- [allowFontScaling]
119-
double setSp(num fontSize, {bool allowFontScalingSelf}) =>
115+
double setSp(num fontSize, {bool? allowFontScalingSelf}) =>
120116
allowFontScalingSelf == null
121117
? (allowFontScaling
122118
? (fontSize * scaleText)

lib/screenutil_init.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import 'screenutil.dart';
55
class ScreenUtilInit extends StatelessWidget {
66
/// A helper widget that initializes [ScreenUtil]
77
ScreenUtilInit({
8-
@required this.child,
8+
required this.child,
99
this.designSize = ScreenUtil.defaultSize,
1010
this.allowFontScaling = false,
11-
Key key,
11+
Key? key,
1212
}) : super(key: key);
1313

1414
final Widget child;

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: flutter_screenutil
22
description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
3-
version: 4.0.0-beta3
3+
version: 5.0.0-nullsafety.0
44
homepage: https://github.com/OpenFlutter/flutter_screenutil
55

66
environment:
7-
sdk: ">=2.6.0 <3.0.0"
7+
sdk: '>=2.12.0-29.10.beta <3.0.0'
88

99
dependencies:
1010
flutter:

0 commit comments

Comments
 (0)