diff --git a/README.md b/README.md index 349cd99..cfad7a5 100644 --- a/README.md +++ b/README.md @@ -6,19 +6,54 @@ Originally motivated by creating a [Flutter email app](https://github.com/enough ## Getting Started -1. Create a `MediaProvider`, e.g. - * `UrlMediaProvider('funny.png', 'image/png', 'https://domain.com/resources/funny.png')` - * `AssetMediaProvider('funny.png', 'image/png', 'stuff/funny.png')` +1. `import 'package:enough_media/enough_media.dart';` +2. Create a `MediaProvider`, e.g. + * `UrlMediaProvider('funny.png', 'image/png', 'https://domain.com/resources/funny.png')`, + * `AssetMediaProvider('funny.png', 'image/png', 'stuff/funny.png')`, or * `MemoryMediaProvider('funny.png', 'image/png', data)` // data is a `Uint8List` -2. Either build a `PreviewMediaWidget` or an `InteractiveMediaWidget`. -3. Done :-) +3. Either build a `PreviewMediaWidget` or an `InteractiveMediaWidget`. +4. Done :-) + +## Example +```dart +import 'package:enough_media/enough_media.dart'; +import 'dart:typed_data'; +import 'package:flutter/material.dart'; + + +/// Preview media. +Widget buildPreview(String name, String mimeType, Uint8List data) { + final mediaProvider = MemoryMediaProvider(name, mimeType, data); + return PreviewMediaWidget( + mediaProvider: mediaProvider, + ); +} + +/// Provide interactive media, typically for near-fullscreen experiences: +Widget buildInteractive(String name, String mimeType, Uint8List data) { + final mediaProvider = MemoryMediaProvider(name, mimeType, data); + return InteractiveMediaWidget( + mediaProvider: mediaProvider, + ); +} + +/// Preview media and let enough_media move to the interactive experience with a Hero-based animation: +Widget buildPreviewWithShowInteractiveDelegate( + BuildContext context, String name, String mimeType, Uint8List data) { + final mediaProvider = MemoryMediaProvider(name, mimeType, data); + return PreviewMediaWidget( + mediaProvider: mediaProvider, + showInteractiveDelegate: (media) => Navigator.of(context) + .push(MaterialPageRoute(builder: (_) => Scaffold(body: media))), + ); +}``` ## API Documentation Check out the full API documentation at https://pub.dev/documentation/enough_media/latest/ ## Installation -Add this dependencies your pubspec.yaml file: +Add this dependency your pubspec.yaml file: ``` dependencies: