Skip to content

Commit d1cdcbf

Browse files
authored
Merge pull request #192 from GetStream/upload_widget
2 parents d35bd0b + 4271fe8 commit d1cdcbf

25 files changed

+383
-408
lines changed

packages/stream_feed_flutter/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 46;
6+
objectVersion = 50;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -156,7 +156,7 @@
156156
97C146E61CF9000F007C117D /* Project object */ = {
157157
isa = PBXProject;
158158
attributes = {
159-
LastUpgradeCheck = 1020;
159+
LastUpgradeCheck = 1300;
160160
ORGANIZATIONNAME = "";
161161
TargetAttributes = {
162162
97C146ED1CF9000F007C117D = {

packages/stream_feed_flutter/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1300"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

packages/stream_feed_flutter/example/ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@
4141
</array>
4242
<key>UIViewControllerBasedStatusBarAppearance</key>
4343
<false/>
44+
<key>NSPhotoLibraryUsageDescription</key>
45+
<string>Photo Library Access Warning</string>
4446
</dict>
4547
</plist>

packages/stream_feed_flutter/example/pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ dependencies:
3434

3535
# The following adds the Cupertino Icons font to your application.
3636
# Use with the CupertinoIcons class for iOS style icons.
37-
cupertino_icons: ^1.0.2
38-
material_design_icons_flutter: ^5.0.6295
39-
google_fonts: ^2.1.0
37+
cupertino_icons: ^1.0.4
38+
google_fonts: ^2.2.0
39+
image_picker: ^0.8.4+4
40+
material_design_icons_flutter: ^5.0.6595
4041

4142
dev_dependencies:
4243
flutter_test:

packages/stream_feed_flutter/lib/src/media/fullscreen_media.dart

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ class FullscreenMedia extends StatefulWidget {
1313
/// Builds a [FullscreenMedia].
1414
const FullscreenMedia({
1515
Key? key,
16-
required this.media,
16+
required this.attachments,
1717
this.startIndex = 0,
1818
}) : super(key: key);
1919

2020
/// The media to display.
2121
///
2222
/// Can be audio, images, or videos.
23-
final List<MediaUri> media;
23+
final List<Attachment> attachments;
2424

2525
/// The first index of the media being shown.
2626
final int startIndex;
@@ -31,7 +31,7 @@ class FullscreenMedia extends StatefulWidget {
3131
@override
3232
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
3333
super.debugFillProperties(properties);
34-
properties.add(IterableProperty<MediaUri>('media', media));
34+
properties.add(IterableProperty<Attachment>('attachments', attachments));
3535
properties.add(IntProperty('startIndex', startIndex));
3636
}
3737
}
@@ -60,10 +60,10 @@ class FullscreenMediaState extends State<FullscreenMedia>
6060
);
6161
_pageController = PageController(initialPage: widget.startIndex);
6262
_currentPage = widget.startIndex;
63-
for (final media in widget.media) {
64-
if (media.type != MediaType.video) continue;
63+
for (final media in widget.attachments) {
64+
if (media.mediaType != MediaType.video) continue;
6565
final package = VideoPackage(media, showControls: true);
66-
videoPackages[media.uri.toString()] = package;
66+
videoPackages[media.url] = package;
6767
}
6868
_initializePlayers();
6969
}
@@ -96,15 +96,15 @@ class FullscreenMediaState extends State<FullscreenMedia>
9696
builder: (context, child) {
9797
return PageView.builder(
9898
controller: _pageController,
99-
itemCount: widget.media.length,
99+
itemCount: widget.attachments.length,
100100
onPageChanged: (val) {
101101
setState(() => _currentPage = val);
102102
},
103103
itemBuilder: (context, index) {
104-
final media = widget.media[index];
105-
if (media.type == MediaType.image && media.isValidUrl) {
104+
final media = widget.attachments[index];
105+
if (media.mediaType == MediaType.image) {
106106
return PhotoView(
107-
imageProvider: NetworkImage(media.uri.toString()),
107+
imageProvider: NetworkImage(media.url),
108108
maxScale: PhotoViewComputedScale.covered,
109109
minScale: PhotoViewComputedScale.contained,
110110
onTapUp: (a, b, c) {
@@ -121,9 +121,8 @@ class FullscreenMediaState extends State<FullscreenMedia>
121121
);
122122
},
123123
);
124-
} else if (media.type == MediaType.video &&
125-
media.isValidUrl) {
126-
final controller = videoPackages[media.uri.toString()];
124+
} else if (media.mediaType == MediaType.video) {
125+
final controller = videoPackages[media.url];
127126
if (controller != null && !controller.initialized) {
128127
return const Center(
129128
child: CircularProgressIndicator(),
@@ -160,7 +159,7 @@ class FullscreenMediaState extends State<FullscreenMedia>
160159
children: [
161160
GalleryHeader(
162161
currentIndex: _currentPage,
163-
totalMedia: widget.media.length,
162+
totalMedia: widget.attachments.length,
164163
onBackButtonPressed: () => Navigator.of(context).pop(),
165164
),
166165
],

packages/stream_feed_flutter/lib/src/media/gallery_preview.dart

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:stream_feed_flutter/src/media/fullscreen_media.dart';
4-
53
import 'package:stream_feed_flutter/src/media/media_widget.dart';
64
import 'package:stream_feed_flutter/stream_feed_flutter.dart';
75

@@ -12,11 +10,11 @@ class GalleryPreview extends StatelessWidget {
1210
/// Builds a [GalleryPreview].
1311
const GalleryPreview({
1412
Key? key,
15-
required this.media,
13+
required this.attachments,
1614
}) : super(key: key);
1715

1816
/// The list of image urls to display
19-
final List<MediaUri> media;
17+
final List<Attachment> attachments;
2018

2119
@override
2220
Widget build(BuildContext context) {
@@ -38,26 +36,26 @@ class GalleryPreview extends StatelessWidget {
3836
direction: Axis.horizontal,
3937
children: [
4038
FlexibleImage(
41-
media: media,
39+
attachments: attachments,
4240
child: MediaWidget(
43-
media: media[0],
41+
attachment: attachments[0],
4442
),
4543
),
46-
if (media.length >= 2)
44+
if (attachments.length >= 2)
4745
FlexibleImage(
48-
media: media,
46+
attachments: attachments,
4947
index: 1,
5048
child: Padding(
5149
padding: const EdgeInsets.only(left: 2),
5250
child: MediaWidget(
53-
media: media[1],
51+
attachment: attachments[1],
5452
),
5553
),
5654
),
5755
],
5856
),
5957
),
60-
if (media.length >= 3)
58+
if (attachments.length >= 3)
6159
Flexible(
6260
fit: FlexFit.tight,
6361
child: Padding(
@@ -67,33 +65,33 @@ class GalleryPreview extends StatelessWidget {
6765
crossAxisAlignment: CrossAxisAlignment.stretch,
6866
children: [
6967
FlexibleImage(
70-
media: media,
68+
attachments: attachments,
7169
index: 2,
7270
child: MediaWidget(
73-
media: media[2],
71+
attachment: attachments[2],
7472
),
7573
),
76-
if (media.length >= 4)
74+
if (attachments.length >= 4)
7775
FlexibleImage(
78-
media: media,
76+
attachments: attachments,
7977
index: 3,
8078
child: Padding(
8179
padding: const EdgeInsets.only(left: 2),
8280
child: Stack(
8381
fit: StackFit.expand,
8482
children: [
8583
MediaWidget(
86-
media: media[3],
84+
attachment: attachments[3],
8785
),
88-
if (media.length > 4)
86+
if (attachments.length > 4)
8987
Positioned.fill(
9088
child: GestureDetector(
9189
onTap: () => _onTap(context, 3),
9290
child: Material(
9391
color: Colors.black38,
9492
child: Center(
9593
child: Text(
96-
'+ ${media.length - 4}',
94+
'+ ${attachments.length - 4}',
9795
style: const TextStyle(
9896
color: Colors.white,
9997
fontSize: 26,
@@ -121,7 +119,7 @@ class GalleryPreview extends StatelessWidget {
121119
MaterialPageRoute(
122120
builder: (context) => FullscreenMedia(
123121
startIndex: index,
124-
media: media,
122+
attachments: attachments,
125123
),
126124
),
127125
);
@@ -130,7 +128,7 @@ class GalleryPreview extends StatelessWidget {
130128
@override
131129
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
132130
super.debugFillProperties(properties);
133-
properties.add(IterableProperty<MediaUri>('media', media));
131+
properties.add(IterableProperty<Attachment>('attachments', attachments));
134132
}
135133
}
136134

@@ -139,7 +137,7 @@ class FlexibleImage extends StatelessWidget {
139137
/// Builds a [FlexibleImage].
140138
const FlexibleImage({
141139
Key? key,
142-
required this.media,
140+
required this.attachments,
143141
this.index = 0,
144142
this.child,
145143
this.flexFit = FlexFit.tight,
@@ -155,7 +153,7 @@ class FlexibleImage extends StatelessWidget {
155153
final int index;
156154

157155
/// The media being shown.
158-
final List<MediaUri> media;
156+
final List<Attachment> attachments;
159157

160158
@override
161159
Widget build(BuildContext context) {
@@ -167,7 +165,7 @@ class FlexibleImage extends StatelessWidget {
167165
MaterialPageRoute(
168166
builder: (context) => FullscreenMedia(
169167
startIndex: index,
170-
media: media,
168+
attachments: attachments,
171169
),
172170
),
173171
);
@@ -182,6 +180,6 @@ class FlexibleImage extends StatelessWidget {
182180
super.debugFillProperties(properties);
183181
properties.add(EnumProperty<FlexFit>('flexFit', flexFit));
184182
properties.add(IntProperty('index', index));
185-
properties.add(IterableProperty<MediaUri>('media', media));
183+
properties.add(IterableProperty<Attachment>('attachments', attachments));
186184
}
187185
}

packages/stream_feed_flutter/lib/src/media/media_widget.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ import 'package:video_thumbnail/video_thumbnail.dart';
99
/// {@template mediaWidget}
1010
/// Displays various kinds of [Media].
1111
///
12-
/// If the [media] is a video, it will display a thumbnail.
12+
/// If the [attachment] is a video, it will display a thumbnail.
1313
/// {@endtemplate}
1414
class MediaWidget extends StatefulWidget {
1515
/// {@macro mediaWidget}
1616
const MediaWidget({
1717
Key? key,
18-
required this.media,
18+
required this.attachment,
1919
}) : super(key: key);
2020

2121
/// The media to display.
22-
final MediaUri media;
22+
final Attachment attachment;
2323

2424
@override
2525
_MediaWidgetState createState() => _MediaWidgetState();
2626

2727
@override
2828
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
2929
super.debugFillProperties(properties);
30-
properties.add(DiagnosticsProperty<MediaUri>('media', media));
30+
properties.add(DiagnosticsProperty<Attachment>('attachment', attachment));
3131
}
3232
}
3333

@@ -38,10 +38,10 @@ class _MediaWidgetState extends State<MediaWidget> {
3838
void didChangeDependencies() {
3939
super.didChangeDependencies();
4040
final mediaQuery = MediaQuery.of(context);
41-
if (widget.media.runtimeType == MediaType.video) {
41+
if (widget.attachment.runtimeType == MediaType.video) {
4242
_getThumbnail = getTemporaryDirectory().then((result) {
4343
return VideoThumbnail.thumbnailFile(
44-
video: widget.media.uri.toString(),
44+
video: widget.attachment.url,
4545
thumbnailPath: result.path,
4646
maxWidth: mediaQuery.size.width ~/ 2,
4747
quality: 75,
@@ -52,12 +52,12 @@ class _MediaWidgetState extends State<MediaWidget> {
5252

5353
@override
5454
Widget build(BuildContext context) {
55-
if (widget.media.type == MediaType.image) {
55+
if (widget.attachment.mediaType == MediaType.image) {
5656
return Image.network(
57-
widget.media.uri.toString(),
57+
widget.attachment.url,
5858
fit: BoxFit.cover,
5959
);
60-
} else if (widget.media.type == MediaType.video) {
60+
} else if (widget.attachment.mediaType == MediaType.video) {
6161
return FutureBuilder<String?>(
6262
future: _getThumbnail,
6363
builder: (context, snapshot) {
@@ -80,7 +80,7 @@ class _MediaWidgetState extends State<MediaWidget> {
8080
},
8181
);
8282
} else {
83-
return Container();
83+
return const SizedBox.shrink();
8484
}
8585
}
8686
}

packages/stream_feed_flutter/lib/src/media/video_package.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import 'package:video_player/video_player.dart';
99
class VideoPackage {
1010
/// Constructor for creating [VideoPackage]
1111
VideoPackage(
12-
MediaUri media, {
12+
Attachment media, {
1313
bool showControls = false,
1414
bool autoInitialize = true,
1515
}) : _showControls = showControls,
1616
_autoInitialize = autoInitialize,
17-
_videoPlayerController =
18-
VideoPlayerController.network(media.uri.toString());
17+
_videoPlayerController = VideoPlayerController.network(media.url);
1918

2019
final bool _showControls;
2120
final bool _autoInitialize;

packages/stream_feed_flutter/lib/src/widgets/activity/content.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ class ActivityContent extends StatelessWidget {
4040
final detector = TagDetector(); //TODO: move this higher in the widget tree
4141
final activityObject = activity.object;
4242
final attachments =
43-
activity.extraData?['attachments']; //TODO: attachment builder
43+
activity.extraData?.toAttachments(); //TODO: attachment builder
4444
final taggedText = activityObject != null
4545
? detector.parseText(activityObject)
4646
: <TaggedText>[];
4747
return Padding(
4848
padding: const EdgeInsets.only(left: 8, right: 8),
4949
child: Column(
50+
crossAxisAlignment: CrossAxisAlignment.start,
5051
children: [
5152
Wrap(
5253
//TODO: move to Text.rich(WidgetSpans)
@@ -59,11 +60,9 @@ class ActivityContent extends StatelessWidget {
5960
))
6061
.toList(),
6162
),
62-
//TODO: handle Video + Audio + Gallery
63-
if (attachments != null)
64-
ActivityCard(
65-
og: OpenGraphData.fromJson(attachments as Map<String, dynamic>),
66-
)
63+
ActivityCard(
64+
attachments: attachments,
65+
),
6766
],
6867
),
6968
);

0 commit comments

Comments
 (0)