asset_copy 0.0.1 asset_copy: ^0.0.1 copied to clipboard
The Asset Copy Plugin allows you to copy files from the Flutter app's assets to the device's local file system on both Android and iOS. This is useful when you need to manipulate or access large files [...]
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:asset_copy/asset_copy.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _statusMessage = 'Copying asset...';
@override
void initState() {
super.initState();
copyAssetToLocal();
}
Future<void> copyAssetToLocal() async {
String status;
try {
const assetName = 'example.json';
const targetPath = 'example.json';
await AssetCopy.copyAssetToLocalStorage(assetName, targetPath);
status = 'File copied successfully to $targetPath';
} on PlatformException catch (e) {
status = 'Failed to copy asset: ${e.message}';
}
if (!mounted) return;
setState(() {
_statusMessage = status;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text(_statusMessage),
),
),
);
}
}