x_storage_flutter
A package that provides Flutter widgets and services for XStorage. It includes Flutter-specific features such as image display widgets and audio playback services.
Features
XStorageImage: A widget that displays images from XStorage URIsXStorageAudioService: A service that plays audio from XStorage URIs
Getting Started
Installation
dependencies:
x_storage_flutter: ^0.0.1
x_storage_core: ^0.0.1
Image Display
import 'package:x_storage_flutter/x_storage_flutter.dart';
import 'package:x_storage_core/x_storage_core.dart';
// Create and configure XStorage instance
final storage = XStorage();
// Register drivers...
// Display an image
XStorageImage(
uri: XUri.create('my_storage', 'path/to/image.jpg'),
xStorage: storage,
width: 200,
height: 200,
fit: BoxFit.cover,
)
ImageProvider
XStorageImageProvider reads the image through XStorage.loadFile, so it works
anywhere an ImageProvider is accepted (DecorationImage, Image with
frameBuilder / errorBuilder, precacheImage). With CachingStorageProvider,
the first display saves the file to the device cache.
DecoratedBox(
decoration: BoxDecoration(
color: Colors.pink.shade50, // shown while loading or on failure
image: DecorationImage(
image: XStorageImageProvider(
XUri.create('cdn', 'backgrounds/cafe.webp'),
storage,
),
fit: BoxFit.cover,
),
),
)
Audio Playback
import 'package:x_storage_flutter/x_storage_flutter.dart';
import 'package:x_storage_core/x_storage_core.dart';
// Create and configure XStorage instance
final storage = XStorage();
// Register drivers...
// Create audio service
final audioService = XStorageAudioService(storage);
// Play audio
await audioService.play(
XUri.create('my_storage', 'path/to/audio.mp3'),
);
// Stop playback
await audioService.stop();
Important Notes
XStorageImageautomatically detects the storage type and displays images accordinglyXStorageAudioServicecurrently only supports network-based storage- Consider implementing appropriate caching and redraw timing based on your use case
License
This project is licensed under the MIT License - see the LICENSE file for details.