### Example App UI for MediaStore Plus Source: https://pub.dev/packages/media_store_plus/example This widget displays the main UI of the example application. It includes buttons to navigate to different screens for saving media files (images, audio, video) in various directories and for performing read/write operations on API 33+. ```Dart @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('media_store_plus_example'), ), body: Center( child: Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, children: [ Text.rich( TextSpan(text: 'Running on: ', children: [ TextSpan( text: _platformSDKVersion.toString(), style: const TextStyle( fontWeight: FontWeight.bold, )), ]), ), const SizedBox( height: 10, ), const Text( 'Save file in...', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20), ), const SizedBox( height: 20, ), ElevatedButton( onPressed: () { Navigator.of(context) .push(MaterialPageRoute(builder: (context) { return const ImageSaveScreen(); })); }, child: const Text("Image Folder"), ), ElevatedButton( onPressed: () { Navigator.of(context) .push(MaterialPageRoute(builder: (context) { return const AudioSaveScreen( dirType: DirType.audio, ); })); }, child: const Text("Audio Folder"), ), ElevatedButton( onPressed: () { Navigator.of(context) .push(MaterialPageRoute(builder: (context) { return const VideoSaveScreen(); })); }, child: const Text("Video Folder"), ), ElevatedButton( onPressed: () { Navigator.of(context) .push(MaterialPageRoute(builder: (context) { return const AudioSaveScreen( dirType: DirType.download, ); })); }, child: const Text("Download Folder"), ), ElevatedButton( onPressed: () { Navigator.of(context) .push(MaterialPageRoute(builder: (context) { return const ReadWriteScreenAPI33OrUp(); })); }, child: const Text("Read/Write API 33 or Upper Folder"), ), ], ), ), ); } } ``` -------------------------------- ### Initialize MediaStore Plus and Request Permissions Source: https://pub.dev/packages/media_store_plus/example This snippet shows the main setup for the media_store_plus plugin in a Flutter application. It ensures initialization for Android, requests necessary storage and media permissions based on the platform's SDK version, and sets the application folder for file storage. ```dart import 'dart:async'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:media_store_plus/media_store_plus.dart'; import 'package:media_store_plus_example/screen/AudioSaveScreen.dart'; import 'package:media_store_plus_example/screen/ImageSaveScreen.dart'; import 'package:media_store_plus_example/screen/ReadWriteScreenAPI33OrUp.dart'; import 'package:media_store_plus_example/screen/VideoSaveScreen.dart'; import 'package:permission_handler/permission_handler.dart'; final mediaStorePlugin = MediaStore(); void main() async { WidgetsFlutterBinding.ensureInitialized(); if (Platform.isAndroid) { await MediaStore.ensureInitialized(); } // From API 33, we request photos, audio, videos permission to read these files. This the new way // From API 29, we request storage permission only to read access all files // API lower than 30, we request storage permission to read & write access access all files // For writing purpose, we are using [MediaStore] plugin. It will use MediaStore or java File based on API level. // It will use MediaStore for writing files from API level 30 or use java File lower than 30 List permissions = [ Permission.storage, ]; if ((await mediaStorePlugin.getPlatformSDKInt()) >= 33) { permissions.add(Permission.photos); permissions.add(Permission.audio); permissions.add(Permission.videos); } await permissions.request(); // we are not checking the status as it is an example app. You should (must) check it in a production app // You have set this otherwise it throws AppFolderNotSetException MediaStore.appFolder = "MediaStorePlugin"; runApp( MaterialApp( theme: ThemeData(primarySwatch: Colors.teal), home: const MyApp(), ), ); } class MyApp extends StatefulWidget { const MyApp({super.key}); @override State createState() => _MyAppState(); } class _MyAppState extends State { int _platformSDKVersion = 0; @override void initState() { super.initState(); initPlatformState(); } // Platform messages are asynchronous, so we initialize in an async method. Future initPlatformState() async { int platformSDKVersion; // Platform messages may fail, so we use a try/catch PlatformException. // We also handle the message potentially returning null. try { platformSDKVersion = await mediaStorePlugin.getPlatformSDKInt(); } on PlatformException { platformSDKVersion = -1; } // If the widget was removed from the tree while the asynchronous platform // message was in flight, we want to discard the reply rather than calling // setState to update our non-existent appearance. if (!mounted) return; setState(() { _platformSDKVersion = platformSDKVersion; }); print((await mediaStorePlugin.getFilePathFromUri( uriString: 'content://media/external/images/media/1000000056'))); print((await mediaStorePlugin.getFilePathFromUri( uriString: 'content://media/external_primary/images/media/1000000057'))); } ``` -------------------------------- ### Add media_store_plus Dependency Source: https://pub.dev/packages/media_store_plus Add the media_store_plus plugin to your pubspec.yaml file to include it in your project dependencies. ```yaml dependencies: media_store_plus: ^0.1.3 ``` -------------------------------- ### Import media_store_plus in Dart Source: https://pub.dev/packages/media_store_plus/install Import the media_store_plus package into your Dart files to access its functionalities. ```dart import 'package:media_store_plus/media_store_plus.dart'; ``` -------------------------------- ### Add media_store_plus Dependency Source: https://pub.dev/packages/media_store_plus/install Add the media_store_plus package to your Flutter project's dependencies using the Flutter CLI. ```bash $ flutter pub add media_store_plus ``` -------------------------------- ### Android Manifest Permissions Source: https://pub.dev/packages/media_store_plus Configure AndroidManifest.xml with necessary permissions for reading and writing media files, considering different API levels. This includes permissions for images, audio, video, and external storage access. ```xml android:maxSdkVersion="32" /> android:maxSdkVersion="29" /> ``` -------------------------------- ### MIT License Source: https://pub.dev/packages/media_store_plus/license This is the standard MIT License text. It grants broad permissions for using, copying, modifying, merging, publishing, distributing, sublicensing, and/or selling the software, provided the copyright notice and permission notice are included in all copies or substantial portions of the Software. ```plaintext MIT License Copyright (c) 2021 Shahriar Nasim Nafi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.