filepick 1.2.0
filepick: ^1.2.0 copied to clipboard
WhatsApp and Telegram style media and attachment picker for Flutter: an in-app gallery sheet with a Camera tile first, albums, a Files button, photo cropping, native installed apps query, and an uploa [...]
example/lib/main.dart
import 'package:file_picker/file_picker.dart';
import 'package:filepick/filepick.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const FilePickExampleApp());
}
class FilePickExampleApp extends StatelessWidget {
const FilePickExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'filepick Demo',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
),
home: const DemoHomePage(),
);
}
}
class DemoHomePage extends StatefulWidget {
const DemoHomePage({super.key});
@override
State<DemoHomePage> createState() => _DemoHomePageState();
}
class _DemoHomePageState extends State<DemoHomePage> {
PlatformFile? _attachment;
CroppedImage? _croppedImage;
bool _isUploading = false;
Future<void> _handlePickAttachment() async {
final file = await pickAttachment(
context,
extensions: ['jpg', 'png', 'pdf', 'mp4'],
title: 'Select Attachment',
);
if (file != null) {
setState(() => _attachment = file);
}
}
Future<void> _handlePickAndCropProfile() async {
final cropped = await pickAndCropImage(
context,
title: 'Crop Avatar',
aspectRatio: 1.0,
circle: true,
fileName: 'avatar.jpg',
);
if (cropped != null) {
setState(() {
_croppedImage = cropped;
_isUploading = true;
});
await Future<void>.delayed(const Duration(seconds: 3));
if (mounted) {
setState(() => _isUploading = false);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('filepick Example'),
),
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
const Text('Profile Photo & Upload Ring', style: TextStyle(fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
UploadRing(
active: _isUploading,
strokeWidth: 4,
child: CircleAvatar(
radius: 48,
backgroundImage: _croppedImage != null ? MemoryImage(_croppedImage!.bytes) : null,
child: _croppedImage == null ? const Icon(Icons.person, size: 48) : null,
),
),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: _handlePickAndCropProfile,
icon: const Icon(Icons.crop),
label: const Text('Pick & Crop Profile Photo'),
),
],
),
),
),
const SizedBox(height: 20),
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
const Text('Attachment Picker', style: TextStyle(fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
if (_attachment != null) ...[
Text('Selected file: ${_attachment!.name} (${_attachment!.size} bytes)'),
const SizedBox(height: 12),
],
ElevatedButton.icon(
onPressed: _handlePickAttachment,
icon: const Icon(Icons.attach_file),
label: const Text('Attach File / Photo / Video'),
),
],
),
),
),
],
),
),
),
);
}
}