From 174f3e934177d52c41c017921c34fd11b5af84b7 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Sun, 26 Nov 2023 15:36:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E6=8C=81=E5=B1=8F=E5=B9=95=20?= =?UTF-8?q?=E5=94=A4=E9=86=92=20+=20=E9=9A=90=E8=97=8F=20=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=8A=B6=E6=80=81=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/build.gradle | 26 ++++++- lib/animate/fade.dart | 63 ++++++++++++++++ lib/animate/slide.dart | 74 +++++++++++++++++++ lib/main.dart | 8 +- lib/view/home.dart | 2 +- lib/view/video.dart | 10 ++- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 66 ++++++++++++++++- pubspec.yaml | 1 + 9 files changed, 242 insertions(+), 10 deletions(-) create mode 100644 lib/animate/fade.dart create mode 100644 lib/animate/slide.dart diff --git a/android/build.gradle b/android/build.gradle index f7eb7f6..dd70169 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,8 +1,17 @@ buildscript { ext.kotlin_version = '1.7.10' repositories { - google() - mavenCentral() + maven { url 'https://maven.aliyun.com/repository/google' } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } + maven { + allowInsecureProtocol = true + url 'https://maven.aliyun.com/repository/jcenter' + } + maven { + allowInsecureProtocol = true + url 'http://maven.aliyun.com/nexus/content/groups/public' + } } dependencies { @@ -13,8 +22,17 @@ buildscript { allprojects { repositories { - google() - mavenCentral() + maven { url 'https://maven.aliyun.com/repository/google' } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } + maven { + allowInsecureProtocol = true + url 'https://maven.aliyun.com/repository/jcenter' + } + maven { + allowInsecureProtocol = true + url 'http://maven.aliyun.com/nexus/content/groups/public' + } } } diff --git a/lib/animate/fade.dart b/lib/animate/fade.dart new file mode 100644 index 0000000..a3ba139 --- /dev/null +++ b/lib/animate/fade.dart @@ -0,0 +1,63 @@ +import 'package:flutter/material.dart'; + +class Fade extends StatefulWidget { + final Duration duration; + final Widget child; + + const Fade({ + super.key, + required this.child, + this.duration = const Duration(milliseconds: 500), + }); + + @override + State createState() { + return _FadeTransitionState(); + } +} + +class _FadeTransitionState extends State with TickerProviderStateMixin { + late final AnimationController _controller = AnimationController( + vsync: this, + duration: widget.duration, + )..forward(); + + late final Animation _animation = + // 补间动画 + // Tween( + // begin: 0, + // end: 1, + // ).animate(_controller); + + // 线性动画 + CurvedAnimation(parent: _controller, curve: Curves.decelerate); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.white, + body: Center( + child: FadeTransition( + opacity: _animation, + child: widget.child, + ), + ), + ); + } +} + +Widget fade({ + required Widget child, + Duration duration = const Duration(milliseconds: 100), +}) { + return Fade( + duration: duration, + child: child, + ); +} diff --git a/lib/animate/slide.dart b/lib/animate/slide.dart new file mode 100644 index 0000000..ebd563f --- /dev/null +++ b/lib/animate/slide.dart @@ -0,0 +1,74 @@ +// 滑动动画 +import 'package:flutter/material.dart'; + +class Slide extends StatefulWidget { + final Duration duration; + final Widget child; + + const Slide({ + super.key, + required this.child, + this.duration = const Duration(milliseconds: 1000), + }); + + @override + State createState() { + return _SlideTransitionState(); + } +} + +class _SlideTransitionState extends State with TickerProviderStateMixin { + late final AnimationController _controller = AnimationController( + vsync: this, + duration: widget.duration, + )..forward(); + + late final Animation _animation = +// 补间动画 +// Tween( +// begin: 0, +// end: 1, +// ).animate(_controller); + + // 线性动画 + CurvedAnimation(parent: _controller, curve: Curves.decelerate); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.white, + body: Center( + child: _slide( + animation: _animation, + child: widget.child, + dy: 0, + dx: 1 + ), + ), + ); + } +} + + +AnimatedWidget _slide({ + required Animation animation, + required Widget child, + double dx = 0, + double dy = -1, +}) { + return SlideTransition( + position: animation.drive( + Tween( + begin: Offset(dx, dy), + end: Offset.zero, + ).chain(CurveTween(curve: Curves.easeInOutSine)), + ), + child: child, + ); +} diff --git a/lib/main.dart b/lib/main.dart index f7a53e2..1672111 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,8 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:matrix_flutter_app_v2/animate/slide.dart'; import 'package:matrix_flutter_app_v2/view/home.dart'; import 'package:matrix_flutter_app_v2/view/media_query.dart'; import 'package:matrix_flutter_app_v2/view/video.dart'; +import 'animate/fade.dart'; + void main() { runApp(const MyApp()); } @@ -23,9 +26,10 @@ class MyApp extends StatelessWidget { initialRoute: "/", routes: { '/': (ctx) => const MyHomePage(title: 'Flutter Demo Home Page'), - '/media': (ctx) => const CustomMediaQuery(), + '/media': (ctx) => const Slide(child: CustomMediaQuery()), // '/video': (ctx)=> const CustomVideoPlayer(url: "http://[2409:8087:1e03:21::2]:6060/cms001/ch00000090990000001022/index.m3u8") - '/video': (ctx)=> const CustomVideoPlayer(url: "http://10.10.10.200:20480/d/sk-pi/sk-16t/Movie/%E5%A5%87%E5%BC%82%E5%8D%9A%E5%A3%AB.MP4?sign=6uVNOeLwBBCB-pVUz1WdLnAS7kWtXq6PQJ5TcCrXKFY=:0") + //'/video': (ctx)=> const CustomVideoPlayer(url: "http://10.10.10.200:20480/d/sk-pi/sk-16t/Movie/%E5%A5%87%E5%BC%82%E5%8D%9A%E5%A3%AB.MP4?sign=6uVNOeLwBBCB-pVUz1WdLnAS7kWtXq6PQJ5TcCrXKFY=:0") + '/video': (ctx)=> const CustomVideoPlayer(url: "http://[2409:8087:2001:20:2800:0:df6e:eb27]:80/wh7f454c46tw3352677969_1732462333/ott.mobaibox.com/PLTV/3/224/3221228524/index.m3u8") }, ); } diff --git a/lib/view/home.dart b/lib/view/home.dart index 7fbefe2..1898854 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'dart:io' show Platform; + class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); diff --git a/lib/view/video.dart b/lib/view/video.dart index ddff250..a6f5209 100644 --- a/lib/view/video.dart +++ b/lib/view/video.dart @@ -6,6 +6,8 @@ import 'package:flutter/services.dart'; import 'package:video_player/video_player.dart'; import 'dart:math'; +import 'package:wakelock/wakelock.dart'; + class CustomVideoPlayer extends StatefulWidget { final String url; @@ -26,9 +28,10 @@ class _CustomVideoPlayerState extends State { void initState() { super.initState(); WidgetsFlutterBinding.ensureInitialized(); + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom]); SystemChrome.setPreferredOrientations( [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]); - + Wakelock.enable(); initVideoPlayer(); // initFijkPlayer(); } @@ -117,6 +120,7 @@ class _CustomVideoPlayerState extends State { // appBar: AppBar( // toolbarHeight: 35, // ), + backgroundColor: Colors.black, body: player == null ? PopScope( onPopInvoked: (val) { @@ -173,9 +177,11 @@ class _CustomVideoPlayerState extends State { @override void dispose() { - super.dispose(); + Wakelock.disable(); + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top]); SystemChrome.setPreferredOrientations([]); player?.stop().then((value) => player?.dispose()); _controller?.dispose(); + super.dispose(); } } diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index e292918..4d80e46 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,7 +6,9 @@ import FlutterMacOS import Foundation import video_player_avfoundation +import wakelock_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin")) + WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index a450412..77e0a01 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -65,6 +65,14 @@ packages: url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" source: hosted version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878" + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "2.1.0" fijkplayer: dependency: "direct main" description: @@ -104,6 +112,14 @@ packages: url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" source: hosted version: "0.15.4" + js: + dependency: transitive + description: + name: js + sha256: cf7243a0c29626284ada2add68a33f5b1102affe3509393e75136e0f6616bd68 + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "0.6.8" lints: dependency: transitive description: @@ -253,6 +269,46 @@ packages: url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" source: hosted version: "2.1.2" + wakelock: + dependency: "direct main" + description: + name: wakelock + sha256: "769ecf42eb2d07128407b50cb93d7c10bd2ee48f0276ef0119db1d25cc2f87db" + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "0.6.2" + wakelock_macos: + dependency: transitive + description: + name: wakelock_macos + sha256: "047c6be2f88cb6b76d02553bca5a3a3b95323b15d30867eca53a19a0a319d4cd" + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "0.4.0" + wakelock_platform_interface: + dependency: transitive + description: + name: wakelock_platform_interface + sha256: "1f4aeb81fb592b863da83d2d0f7b8196067451e4df91046c26b54a403f9de621" + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "0.3.0" + wakelock_web: + dependency: transitive + description: + name: wakelock_web + sha256: "1b256b811ee3f0834888efddfe03da8d18d0819317f20f6193e2922b41a501b5" + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "0.4.0" + wakelock_windows: + dependency: transitive + description: + name: wakelock_windows + sha256: "857f77b3fe6ae82dd045455baa626bc4b93cb9bb6c86bf3f27c182167c3a5567" + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "0.2.1" web: dependency: transitive description: @@ -261,6 +317,14 @@ packages: url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" source: hosted version: "0.3.0" + win32: + dependency: transitive + description: + name: win32 + sha256: a6f0236dbda0f63aa9a25ad1ff9a9d8a4eaaa5012da0dc59d21afdb1dc361ca4 + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "3.1.4" sdks: dart: ">=3.2.0-194.0.dev <4.0.0" - flutter: ">=1.12.0" + flutter: ">=3.13.0" diff --git a/pubspec.yaml b/pubspec.yaml index e89cd71..fc2d56a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: cupertino_icons: ^1.0.2 fijkplayer: ^0.11.0 video_player: ^2.8.1 + wakelock: ^0.6.2 dev_dependencies: flutter_test: