|
@@ -0,0 +1,151 @@
|
|
|
+import 'dart:io';
|
|
|
+
|
|
|
+import 'package:fis_lib_report/pages/components/vid.dart';
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:vid/us/vid_us_image.dart';
|
|
|
+
|
|
|
+class VidImageView {
|
|
|
+ /// 创建一个从网络链接加载Vid图片的组件
|
|
|
+ ///
|
|
|
+ /// [url] vid图片链接
|
|
|
+ ///
|
|
|
+ /// 其他参数参考[Image]组件
|
|
|
+ static Widget network(
|
|
|
+ String url, {
|
|
|
+ Key? key,
|
|
|
+ double? width,
|
|
|
+ double? height,
|
|
|
+ Widget Function(BuildContext context)? loadingBuilder,
|
|
|
+ ImageErrorWidgetBuilder? errorBuilder,
|
|
|
+ Animation<double>? opacity,
|
|
|
+ FilterQuality filterQuality = FilterQuality.low,
|
|
|
+ BlendMode? colorBlendMode,
|
|
|
+ BoxFit? fit,
|
|
|
+ Alignment alignment = Alignment.center,
|
|
|
+ bool isAntiAlias = false,
|
|
|
+ bool gaplessPlayback = false,
|
|
|
+ double scale = 1.0,
|
|
|
+ }) {
|
|
|
+ return FutureBuilder(
|
|
|
+ future: VidFileHelper.getImageFromNetwork(url),
|
|
|
+ builder: (context, snapshot) => _buildAsyncVidWidget(
|
|
|
+ context,
|
|
|
+ snapshot,
|
|
|
+ loadingBuilder,
|
|
|
+ errorBuilder,
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ opacity: opacity,
|
|
|
+ filterQuality: filterQuality,
|
|
|
+ colorBlendMode: colorBlendMode,
|
|
|
+ fit: fit,
|
|
|
+ alignment: alignment,
|
|
|
+ isAntiAlias: isAntiAlias,
|
|
|
+ gaplessPlayback: gaplessPlayback,
|
|
|
+ scale: scale,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 创建一个从文件加载Vid图片的组件
|
|
|
+ ///
|
|
|
+ /// [file] 文件对象
|
|
|
+ ///
|
|
|
+ /// 其他参数参考[Image]组件
|
|
|
+ static Widget file(
|
|
|
+ File file, {
|
|
|
+ Key? key,
|
|
|
+ double? width,
|
|
|
+ double? height,
|
|
|
+ Widget Function(BuildContext context)? loadingBuilder,
|
|
|
+ ImageErrorWidgetBuilder? errorBuilder,
|
|
|
+ Animation<double>? opacity,
|
|
|
+ FilterQuality filterQuality = FilterQuality.low,
|
|
|
+ BlendMode? colorBlendMode,
|
|
|
+ BoxFit? fit,
|
|
|
+ Alignment alignment = Alignment.center,
|
|
|
+ bool isAntiAlias = false,
|
|
|
+ bool gaplessPlayback = false,
|
|
|
+ double scale = 1.0,
|
|
|
+ }) {
|
|
|
+ return FutureBuilder(
|
|
|
+ future: VidFileHelper.getImageFromFile(file),
|
|
|
+ builder: (context, snapshot) => _buildAsyncVidWidget(
|
|
|
+ context,
|
|
|
+ snapshot,
|
|
|
+ loadingBuilder,
|
|
|
+ errorBuilder,
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ opacity: opacity,
|
|
|
+ filterQuality: filterQuality,
|
|
|
+ colorBlendMode: colorBlendMode,
|
|
|
+ fit: fit,
|
|
|
+ alignment: alignment,
|
|
|
+ isAntiAlias: isAntiAlias,
|
|
|
+ gaplessPlayback: gaplessPlayback,
|
|
|
+ scale: scale,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ static Widget _buildAsyncVidWidget(
|
|
|
+ BuildContext context,
|
|
|
+ AsyncSnapshot<Object?> snapshot,
|
|
|
+ Widget Function(BuildContext context)? loadingBuilder,
|
|
|
+ ImageErrorWidgetBuilder? errorBuilder, {
|
|
|
+ double? width,
|
|
|
+ double? height,
|
|
|
+ Animation<double>? opacity,
|
|
|
+ FilterQuality filterQuality = FilterQuality.low,
|
|
|
+ BlendMode? colorBlendMode,
|
|
|
+ BoxFit? fit,
|
|
|
+ Alignment alignment = Alignment.center,
|
|
|
+ bool isAntiAlias = false,
|
|
|
+ bool gaplessPlayback = false,
|
|
|
+ double scale = 1.0,
|
|
|
+ }) {
|
|
|
+ if (snapshot.connectionState == ConnectionState.done) {
|
|
|
+ if (snapshot.hasData) {
|
|
|
+ final frame = snapshot.data as VidUsImage;
|
|
|
+ return Image.memory(
|
|
|
+ frame.imageData,
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ opacity: opacity,
|
|
|
+ filterQuality: filterQuality,
|
|
|
+ colorBlendMode: colorBlendMode,
|
|
|
+ fit: fit,
|
|
|
+ alignment: alignment,
|
|
|
+ isAntiAlias: isAntiAlias,
|
|
|
+ gaplessPlayback: gaplessPlayback,
|
|
|
+ scale: scale,
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ final exWidget = errorBuilder != null
|
|
|
+ ? errorBuilder(
|
|
|
+ context,
|
|
|
+ Exception("Vid Image load fail."),
|
|
|
+ snapshot.stackTrace,
|
|
|
+ )
|
|
|
+ : ErrorWidget("Error");
|
|
|
+ return Container(
|
|
|
+ alignment: alignment,
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ child: exWidget,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ final loading = loadingBuilder != null
|
|
|
+ ? loadingBuilder(context)
|
|
|
+ : const CircularProgressIndicator();
|
|
|
+ return Container(
|
|
|
+ alignment: alignment,
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ child: loading,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|