asset_widget_builder.dart
2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2019 The FlutterCandies author. All rights reserved.
// Use of this source code is governed by an Apache license that can be found
// in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart'
show AssetEntity, AssetEntityImageProvider, AssetType;
class AssetWidgetBuilder extends StatelessWidget {
const AssetWidgetBuilder({
super.key,
required this.entity,
required this.isDisplayingDetail,
});
final AssetEntity entity;
final bool isDisplayingDetail;
Widget _audioAssetWidget(BuildContext context) {
return ColoredBox(
color: Theme.of(context).dividerColor,
child: Stack(
children: <Widget>[
AnimatedPositionedDirectional(
duration: kThemeAnimationDuration,
top: 0.0,
start: 0.0,
end: 0.0,
bottom: isDisplayingDetail ? 20.0 : 0.0,
child: Center(
child: Icon(
Icons.audiotrack,
size: isDisplayingDetail ? 24.0 : 16.0,
),
),
),
AnimatedPositionedDirectional(
duration: kThemeAnimationDuration,
start: 0.0,
end: 0.0,
bottom: isDisplayingDetail ? 0.0 : -20.0,
height: 20.0,
child: Text(
entity.title ?? '',
style: const TextStyle(height: 1.0, fontSize: 10.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
),
],
),
);
}
Widget _imageAssetWidget(BuildContext context) {
return Image(
image: AssetEntityImageProvider(entity, isOriginal: false),
fit: BoxFit.cover,
);
}
Widget _videoAssetWidget(BuildContext context) {
return Stack(
children: <Widget>[
Positioned.fill(child: _imageAssetWidget(context)),
ColoredBox(
color: Theme.of(context).dividerColor.withOpacity(0.3),
child: Center(
child: Icon(
Icons.video_library,
color: Colors.white,
size: isDisplayingDetail ? 24.0 : 16.0,
),
),
),
],
);
}
@override
Widget build(BuildContext context) {
return switch (entity.type) {
AssetType.audio => _audioAssetWidget(context),
AssetType.video => _videoAssetWidget(context),
AssetType.image || AssetType.other => _imageAssetWidget(context),
};
}
}