flutter_media_scanner 0.0.10 flutter_media_scanner: ^0.0.10 copied to clipboard
Refresh the filesystem after writing a file to Android Gallery
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_media_scanner/flutter_media_scanner.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterMediaScanner example'),
),
body: Center(
child: OutlineButton(
onPressed: () async {
File originalFile = File("path/to/file");
List<int> bytes = await originalFile.readAsBytes();
//save your file to your desired path
File file = File("desired/path");
await file.writeAsBytes(bytes);
//refresh the file system so the file can show in the gallery,
await FlutterMediaScanner.scan(file.path);
},
child: const Text("Save & refresh!"),
),
),
),
);
}
}