mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-16 07:06:14 +08:00
opt context ext
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
74
lib/utils/context_ext.dart
Normal file
74
lib/utils/context_ext.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// from Getx
|
||||
extension ContextExtensions on BuildContext {
|
||||
/// The same of [MediaQuery.of(context).size]
|
||||
Size get mediaQuerySize => MediaQuery.sizeOf(this);
|
||||
|
||||
/// The same of [MediaQuery.of(context).size.height]
|
||||
/// Note: updates when you rezise your screen (like on a browser or
|
||||
/// desktop window)
|
||||
double get height => mediaQuerySize.height;
|
||||
|
||||
/// The same of [MediaQuery.of(context).size.width]
|
||||
/// Note: updates when you rezise your screen (like on a browser or
|
||||
/// desktop window)
|
||||
double get width => mediaQuerySize.width;
|
||||
|
||||
/// similar to [MediaQuery.of(context).padding]
|
||||
ThemeData get theme => Theme.of(this);
|
||||
|
||||
/// Check if dark mode theme is enable
|
||||
bool get isDarkMode => (theme.brightness == Brightness.dark);
|
||||
|
||||
/// give access to Theme.of(context).iconTheme.color
|
||||
Color? get iconColor => theme.iconTheme.color;
|
||||
|
||||
/// similar to [MediaQuery.of(context).padding]
|
||||
TextTheme get textTheme => Theme.of(this).textTheme;
|
||||
|
||||
/// similar to [MediaQuery.of(context).padding]
|
||||
EdgeInsets get mediaQueryPadding => MediaQuery.paddingOf(this);
|
||||
|
||||
/// similar to [MediaQuery.of(context).padding]
|
||||
MediaQueryData get mediaQuery => MediaQuery.of(this);
|
||||
|
||||
/// similar to [MediaQuery.of(context).viewPadding]
|
||||
EdgeInsets get mediaQueryViewPadding => MediaQuery.viewPaddingOf(this);
|
||||
|
||||
/// similar to [MediaQuery.of(context).viewInsets]
|
||||
EdgeInsets get mediaQueryViewInsets => MediaQuery.viewInsetsOf(this);
|
||||
|
||||
/// similar to [MediaQuery.of(context).orientation]
|
||||
Orientation get orientation => MediaQuery.orientationOf(this);
|
||||
|
||||
/// check if device is on landscape mode
|
||||
bool get isLandscape => orientation == Orientation.landscape;
|
||||
|
||||
/// check if device is on portrait mode
|
||||
bool get isPortrait => orientation == Orientation.portrait;
|
||||
|
||||
/// similar to [MediaQuery.of(this).devicePixelRatio]
|
||||
double get devicePixelRatio => MediaQuery.devicePixelRatioOf(this);
|
||||
|
||||
/// similar to [MediaQuery.of(this).textScaleFactor]
|
||||
double get textScaleFactor => MediaQuery.textScaleFactorOf(this);
|
||||
|
||||
/// get the shortestSide from screen
|
||||
double get mediaQueryShortestSide => mediaQuerySize.shortestSide;
|
||||
|
||||
/// True if width be larger than 800
|
||||
bool get showNavbar => (width > 800);
|
||||
|
||||
/// True if the shortestSide is smaller than 600p
|
||||
bool get isPhone => (mediaQueryShortestSide < 600);
|
||||
|
||||
/// True if the shortestSide is largest than 600p
|
||||
bool get isSmallTablet => (mediaQueryShortestSide >= 600);
|
||||
|
||||
/// True if the shortestSide is largest than 720p
|
||||
bool get isLargeTablet => (mediaQueryShortestSide >= 720);
|
||||
|
||||
/// True if the current device is Tablet
|
||||
bool get isTablet => isSmallTablet || isLargeTablet;
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/hero_dialog_route.dart';
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pbenum.dart'
|
||||
show IMSettingType, ThreeDotItemType;
|
||||
import 'package:PiliPlus/models/common/image_preview_type.dart';
|
||||
import 'package:PiliPlus/pages/common/common_whisper_controller.dart';
|
||||
import 'package:PiliPlus/pages/contact/view.dart';
|
||||
import 'package:PiliPlus/pages/whisper_settings/view.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:floating/floating.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@@ -81,32 +77,9 @@ extension StringExt on String? {
|
||||
bool get isNullOrEmpty => this == null || this!.isEmpty;
|
||||
}
|
||||
|
||||
extension BuildContextExt on BuildContext {
|
||||
Color get vipColor {
|
||||
return Theme.of(this).brightness == Brightness.light
|
||||
? const Color(0xFFFF6699)
|
||||
: const Color(0xFFD44E7D);
|
||||
}
|
||||
|
||||
Future<void> imageView({
|
||||
int initialPage = 0,
|
||||
required List<SourceModel> imgList,
|
||||
ValueChanged<int>? onDismissed,
|
||||
int? quality,
|
||||
}) {
|
||||
bool isMemberPage = Get.currentRoute.startsWith('/member?');
|
||||
return Navigator.of(this).push(
|
||||
HeroDialogRoute(
|
||||
builder: (context) => InteractiveviewerGallery(
|
||||
sources: imgList,
|
||||
initIndex: initialPage,
|
||||
onDismissed: onDismissed,
|
||||
setStatusBar: !isMemberPage,
|
||||
quality: quality ?? GlobalData().imgQuality,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
extension ColorSchemeExt on ColorScheme {
|
||||
Color get vipColor =>
|
||||
brightness.isLight ? const Color(0xFFFF6699) : const Color(0xFFD44E7D);
|
||||
}
|
||||
|
||||
extension Unique<E, Id> on List<E> {
|
||||
@@ -125,8 +98,11 @@ extension ColorExtension on Color {
|
||||
}
|
||||
|
||||
extension BrightnessExt on Brightness {
|
||||
Brightness get reverse =>
|
||||
this == Brightness.light ? Brightness.dark : Brightness.light;
|
||||
Brightness get reverse => isLight ? Brightness.dark : Brightness.light;
|
||||
|
||||
bool get isLight => this == Brightness.light;
|
||||
|
||||
bool get isDark => this == Brightness.dark;
|
||||
}
|
||||
|
||||
extension RationalExt on Rational {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/hero_dialog_route.dart';
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart';
|
||||
import 'package:PiliPlus/grpc/im.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
@@ -17,6 +18,7 @@ import 'package:PiliPlus/pages/video/introduction/ugc/widgets/menu_row.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/controller.dart';
|
||||
import 'package:PiliPlus/services/shutdown_timer_service.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/context_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
@@ -29,10 +31,30 @@ import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' show FilteringTextInputFormatter;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get.dart' hide ContextExtensionss;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class PageUtils {
|
||||
static Future<void> imageView({
|
||||
int initialPage = 0,
|
||||
required List<SourceModel> imgList,
|
||||
ValueChanged<int>? onDismissed,
|
||||
int? quality,
|
||||
}) {
|
||||
bool isMemberPage = Get.currentRoute.startsWith('/member?');
|
||||
return Navigator.of(Get.context!).push(
|
||||
HeroDialogRoute(
|
||||
builder: (context) => InteractiveviewerGallery(
|
||||
sources: imgList,
|
||||
initIndex: initialPage,
|
||||
onDismissed: onDismissed,
|
||||
setStatusBar: !isMemberPage,
|
||||
quality: quality ?? GlobalData().imgQuality,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> pmShare(
|
||||
BuildContext context, {
|
||||
required Map content,
|
||||
@@ -625,7 +647,7 @@ class PageUtils {
|
||||
barrierLabel: '',
|
||||
barrierDismissible: true,
|
||||
pageBuilder: (buildContext, animation, secondaryAnimation) {
|
||||
return MediaQuery.orientationOf(Get.context!) == Orientation.portrait
|
||||
return Get.context!.isPortrait
|
||||
? SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -647,8 +669,7 @@ class PageUtils {
|
||||
},
|
||||
transitionDuration: const Duration(milliseconds: 350),
|
||||
transitionBuilder: (context, animation, secondaryAnimation, child) {
|
||||
Offset begin =
|
||||
MediaQuery.orientationOf(Get.context!) == Orientation.portrait
|
||||
Offset begin = Get.context!.isPortrait
|
||||
? const Offset(0.0, 1.0)
|
||||
: const Offset(1.0, 0.0);
|
||||
var tween = Tween(
|
||||
|
||||
@@ -23,13 +23,14 @@ import 'package:PiliPlus/pages/dynamics_tab/controller.dart';
|
||||
import 'package:PiliPlus/pages/group_panel/view.dart';
|
||||
import 'package:PiliPlus/pages/later/controller.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/context_ext.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get.dart' hide ContextExtensionss;
|
||||
import 'package:gt3_flutter_plugin/gt3_flutter_plugin.dart';
|
||||
|
||||
class RequestUtils {
|
||||
|
||||
@@ -20,11 +20,12 @@ import 'package:PiliPlus/models/user/danmaku_rule.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/bottom_progress_behavior.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/fullscreen_mode.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart';
|
||||
import 'package:PiliPlus/utils/context_ext.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get.dart' hide ContextExtensionss;
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user