Skip to content

Commit c611625

Browse files
committed
➖ Remove common exports and split out constants.
1 parent c60a7a1 commit c611625

File tree

7 files changed

+148
-5
lines changed

7 files changed

+148
-5
lines changed

lib/src/constants/constants.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
/// [Author] Alex (https://github.com/Alex525)
33
/// [Date] 2020/3/31 16:02
44
///
5+
import 'dart:developer';
6+
7+
import 'package:flutter/foundation.dart';
58
import 'package:flutter/widgets.dart';
69

710
import 'constants.dart';
811

9-
export 'package:flutter_common_exports/flutter_common_exports.dart';
10-
1112
export '../delegates/assets_picker_text_delegate.dart';
1213
export '../delegates/sort_path_delegate.dart';
14+
export '../widget/platform_progress_indicator.dart';
1315

1416
export 'colors.dart';
1517
export 'custom_scroll_physics.dart';
1618
export 'enums.dart';
19+
export 'extensions.dart';
20+
export 'screens.dart';
1721

1822
class Constants {
1923
const Constants._();
@@ -24,3 +28,11 @@ class Constants {
2428
DefaultAssetsPickerTextDelegate();
2529
static SortPathDelegate sortPathDelegate = SortPathDelegate.common;
2630
}
31+
32+
/// Log only in debug mode.
33+
/// 只在调试模式打印
34+
void realDebugPrint(dynamic message) {
35+
if (!kReleaseMode) {
36+
log('$message');
37+
}
38+
}

lib/src/constants/extensions.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2020/8/19 10:34
4+
///
5+
import 'package:flutter/material.dart';
6+
7+
extension BuildContextExtension on BuildContext {
8+
MediaQueryData get mediaQuery => MediaQuery.of(this);
9+
ThemeData get themeData => Theme.of(this);
10+
}
11+
12+
extension BrightnessExtension on Brightness {
13+
bool get isDark => this == Brightness.dark;
14+
bool get isLight => this == Brightness.light;
15+
}
16+
17+
extension ColorExtension on Color {
18+
bool get isTransparent => this == Colors.transparent;
19+
}

lib/src/constants/screens.dart

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2020/8/19 10:29
4+
///
5+
import 'dart:ui' as ui;
6+
7+
import 'package:flutter/material.dart';
8+
import 'package:flutter/services.dart';
9+
10+
/// Screens utils with multiple properties access.
11+
/// 获取屏幕各项属性的工具类
12+
class Screens {
13+
const Screens._();
14+
15+
/// Get [MediaQueryData] from [ui.window]
16+
/// 通过 [ui.window] 获取 [MediaQueryData]
17+
static MediaQueryData get mediaQuery => MediaQueryData.fromWindow(ui.window);
18+
19+
/// The number of device pixels for each logical pixel.
20+
/// 设备每个逻辑像素对应的dp比例
21+
static double get scale => mediaQuery.devicePixelRatio;
22+
23+
/// The horizontal extent of this size.
24+
/// 水平范围的大小
25+
static double get width => mediaQuery.size.width;
26+
27+
/// The horizontal pixels of this size.
28+
/// 水平范围的像素值
29+
static int get widthPixels => (width * scale).toInt();
30+
31+
/// The vertical extent of this size.
32+
/// 垂直范围的大小
33+
static double get height => mediaQuery.size.height;
34+
35+
/// The vertical pixels of this size.
36+
/// 垂直范围的像素值
37+
static int get heightPixels => (height * scale).toInt();
38+
39+
/// Top offset in the [ui.window], usually is the notch size.
40+
/// 从 [ui.window] 获取的顶部偏移(间距),通常是刘海的大小。
41+
static double get topSafeHeight => mediaQuery.padding.top;
42+
43+
/// Bottom offset in the [ui.window], usually is the action bar/navigation bar size.
44+
/// 从 [ui.window] 获取的底部偏移(间距),通常是操作条/导航条的大小。
45+
static double get bottomSafeHeight => mediaQuery.padding.bottom;
46+
47+
/// Height exclude top and bottom safe height.
48+
/// 去除顶部和底部安全区域的高度
49+
static double get safeHeight => height - topSafeHeight - bottomSafeHeight;
50+
51+
/// Method to update status bar's style.
52+
/// 更新状态栏样式的方法
53+
static void updateStatusBarStyle(SystemUiOverlayStyle style) {
54+
SystemChrome.setSystemUIOverlayStyle(style);
55+
}
56+
57+
/// Scale factor for the text.
58+
/// 文字缩放的倍数
59+
static double get textScaleFactor => mediaQuery.textScaleFactor;
60+
61+
/// Return a fixed font size according to text scale factor.
62+
/// 根据文字缩放计算出的固定文字大小
63+
static double fixedFontSize(double fontSize) => fontSize / textScaleFactor;
64+
}

lib/src/widget/builder/audio_page_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _AudioPageBuilderState extends State<AudioPageBuilder> {
7777
Future<void> openAudioFile() async {
7878
try {
7979
final String url = await widget.asset.getMediaUrl();
80-
assetDuration = widget.asset.duration.seconds;
80+
assetDuration = Duration(seconds: widget.asset.duration);
8181
_controller = VideoPlayerController.network(url);
8282
await _controller.initialize();
8383
_controller.addListener(audioPlayerListener);

lib/src/widget/fixed_appbar.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:ui' as ui;
66

77
import 'package:flutter/material.dart';
88
import 'package:flutter/services.dart';
9-
import 'package:flutter_common_exports/flutter_common_exports.dart';
109

1110
import '../constants/constants.dart';
1211

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2020/8/19 10:36
4+
///
5+
import 'dart:io';
6+
7+
import 'package:flutter/cupertino.dart';
8+
import 'package:flutter/material.dart';
9+
10+
/// Progress Indicator. Used in loading data.
11+
class PlatformProgressIndicator extends StatelessWidget {
12+
const PlatformProgressIndicator({
13+
Key key,
14+
this.strokeWidth = 4.0,
15+
this.radius = 10.0,
16+
this.size = 48.0,
17+
this.color,
18+
this.value,
19+
this.brightness,
20+
}) : super(key: key);
21+
22+
final double strokeWidth;
23+
final double radius;
24+
final double size;
25+
final Color color;
26+
final double value;
27+
final Brightness brightness;
28+
29+
bool get isAppleOS => Platform.isIOS || Platform.isMacOS;
30+
31+
@override
32+
Widget build(BuildContext context) {
33+
return SizedBox.fromSize(
34+
size: Size.square(size),
35+
child: isAppleOS
36+
? CupertinoTheme(
37+
data: CupertinoThemeData(
38+
brightness: brightness ?? Brightness.dark,
39+
),
40+
child: CupertinoActivityIndicator(radius: radius),
41+
)
42+
: CircularProgressIndicator(
43+
strokeWidth: strokeWidth,
44+
valueColor:
45+
color != null ? AlwaysStoppedAnimation<Color>(color) : null,
46+
value: value,
47+
),
48+
);
49+
}
50+
}

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dependencies:
1212
sdk: flutter
1313

1414
extended_image: ^1.0.0
15-
flutter_common_exports: ^0.1.0
1615
photo_manager: ^0.5.7
1716
provider: ^4.3.1
1817
video_player: ^0.10.11+2

0 commit comments

Comments
 (0)