forked from aloisdeniel/media_gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
283 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
## 0.1.3 | ||
|
||
* Updated example | ||
* Fixed error when no thumbnail. | ||
|
||
## 0.1.2 | ||
|
||
* Added "All" collection. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:media_gallery/media_gallery.dart'; | ||
|
||
import 'thumbnail.dart'; | ||
import 'labels.dart'; | ||
import 'medias.dart'; | ||
import 'selection.dart'; | ||
|
||
class MediaAlbums extends StatelessWidget { | ||
final List<MediaCollection> collections; | ||
|
||
const MediaAlbums({ | ||
@required this.collections, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
final labels = MediaPickerLabels.of(context); | ||
final selection = MediaPickerSelection.of(context); | ||
final children = collections | ||
.map<Widget>( | ||
(x) => AlbumTile( | ||
collection: x, | ||
onTap: () async { | ||
final result = await Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => MediaPickerSelectionProvider( | ||
selection: selection, | ||
child: MediaPickerLabelsProvider( | ||
value: labels, | ||
child: MediasPage( | ||
collection: x, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
if (result != null) { | ||
Navigator.pop(context, result); | ||
} | ||
}, | ||
), | ||
) | ||
.toList(); | ||
return ListView.separated( | ||
separatorBuilder: (context, i) => Container( | ||
height: 1, | ||
color: theme.textTheme.body1.color.withOpacity(0.12), | ||
), | ||
itemBuilder: (context, i) => children[i], | ||
itemCount: children.length, | ||
); | ||
} | ||
} | ||
|
||
class AlbumTile extends StatelessWidget { | ||
final GestureTapCallback onTap; | ||
final MediaCollection collection; | ||
|
||
const AlbumTile({ | ||
@required this.onTap, | ||
@required this.collection, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
final labels = MediaPickerLabels.of(context); | ||
return InkWell( | ||
onTap: onTap, | ||
child: SafeArea( | ||
top: false, | ||
bottom: false, | ||
child: Padding( | ||
padding: const EdgeInsets.all(12.0), | ||
child: SizedBox( | ||
height: 64, | ||
child: Row( | ||
children: [ | ||
ClipRRect( | ||
borderRadius: BorderRadius.circular(4.0), | ||
child: Container( | ||
width: 64, | ||
height: 64, | ||
color: theme.textTheme.subhead.color.withOpacity(0.1), | ||
child: | ||
MediaCollectionThumbnailImage(collection: collection), | ||
), | ||
), | ||
SizedBox( | ||
width: 12.0, | ||
), | ||
Expanded( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Text( | ||
collection.name, | ||
style: theme.textTheme.subhead, | ||
), | ||
Text( | ||
'${collection.count} ${labels.items}', | ||
style: theme.textTheme.caption, | ||
), | ||
], | ||
), | ||
) | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
@immutable | ||
class MediaPickerLabels { | ||
final String collectionsTitle; | ||
final String items; | ||
final String images; | ||
final String albums; | ||
final String videos; | ||
final String mediaNotAuthorizedAccessTitle; | ||
final String mediaNotAuthorizedAccessDescription; | ||
final String openSettings; | ||
|
||
const MediaPickerLabels({ | ||
@required this.collectionsTitle, | ||
@required this.images, | ||
@required this.videos, | ||
@required this.albums, | ||
@required this.items, | ||
@required this.mediaNotAuthorizedAccessTitle, | ||
@required this.mediaNotAuthorizedAccessDescription, | ||
@required this.openSettings, | ||
}); | ||
|
||
static MediaPickerLabels of(BuildContext context) { | ||
final provider = | ||
context.dependOnInheritedWidgetOfExactType<MediaPickerLabelsProvider>(); | ||
assert(provider != null); | ||
return provider.value; | ||
} | ||
|
||
factory MediaPickerLabels.fallback() => const MediaPickerLabels( | ||
collectionsTitle: 'Select images', | ||
albums: 'Albums', | ||
images: 'Photos', | ||
videos: 'Videos', | ||
items: 'item(s)', | ||
mediaNotAuthorizedAccessTitle: 'Not authorized', | ||
mediaNotAuthorizedAccessDescription: | ||
"This app can't have access to user media gallery. You must update authorizations in app settings.", | ||
openSettings: 'Open settings', | ||
); | ||
} | ||
|
||
class MediaPickerLabelsProvider extends InheritedWidget { | ||
final MediaPickerLabels value; | ||
|
||
const MediaPickerLabelsProvider({ | ||
Key key, | ||
@required Widget child, | ||
@required this.value, | ||
}) : super( | ||
key: key, | ||
child: child, | ||
); | ||
|
||
@override | ||
bool updateShouldNotify(MediaPickerLabelsProvider oldWidget) { | ||
return value != oldWidget.value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.