flutter_file_uploader 0.1.0 copy "flutter_file_uploader: ^0.1.0" to clipboard
flutter_file_uploader: ^0.1.0 copied to clipboard

Flutter widgets that simplify the creation and use of the en_file_uploader library. They include both the UI and business logic for file management.

example/lib/main.dart

import 'dart:io';
import 'dart:math';

import 'package:en_file_uploader/en_file_uploader.dart';
import 'package:example/l10n/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_file_uploader/flutter_file_uploader.dart';

void main() {
  runApp(const App());
}

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        appBarTheme: AppBarTheme(
          backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        ),
        useMaterial3: true,
      ),
      localizationsDelegates: AppLocalizations.localizationsDelegates,
      supportedLocales: AppLocalizations.supportedLocales,
      home: const ShowCase(),
    );
  }
}

class ShowCase extends StatelessWidget {
  const ShowCase({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Center(
                child: FileUploader(
                  builder: (context, ref) {
                    return ProvidedFileCard(
                      ref: ref,
                      content: Text("filename"),
                    );
                  },
                  onPressedAddFiles: () async {
                    await Future.delayed(const Duration(seconds: 1));
                    return [createFile()];
                  },
                  onFileAdded: (file) async {
                    await Future.delayed(const Duration(milliseconds: 500));
                    return MockFileHandler(
                      file: file,
                    );
                  },
                  onFileUploaded: (file) {
                    print("file uploaded ${file.id}");
                  },
                  onFileRemoved: (file) {
                    print("file removed ${file.id}");
                  },
                  placeholder: Text("add a file"),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class MockFileHandler extends FileUploadHandler {
  MockFileHandler({required super.file});

  @override
  Future<void> upload({ProgressCallback? onProgress}) async {
    await Future.delayed(const Duration(seconds: 1));
    return;
  }
}

File createFile({
  int length = 1024,
}) {
  final tempDir = Directory.systemTemp.createTempSync();
  final file = File('${tempDir.path}/file.txt');

  final random = Random();
  final buffer = List<int>.generate(length, (_) => random.nextInt(256));
  file.writeAsBytesSync(buffer);
  return file;
}
6
likes
150
pub points
56%
popularity

Publisher

verified publishermattiapispisa.it

Flutter widgets that simplify the creation and use of the en_file_uploader library. They include both the UI and business logic for file management.

Homepage
Repository (GitHub)
View/report issues

Topics

#file #upload #widget #en-file-uploader

Documentation

API reference

License

MIT (license)

Dependencies

en_file_uploader, flutter, mobkit_dashed_border, provider

More

Packages that depend on flutter_file_uploader