From 56bf8d6e7d60ba2cef2e713b792c692d9e88ec63 Mon Sep 17 00:00:00 2001 From: Robert Virkus Date: Tue, 19 Jan 2021 15:19:16 +0100 Subject: [PATCH] improve base docs --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) 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: