The FileInput component is controlled. Use the `onFilesSelected` callback to handle user interactions.
Selected file: No file selected
class MyUploader extends StatefulComponent { @override State<MyUploader> createState() => _MyUploaderState(); } class _MyUploaderState extends State<MyUploader> { String _fileName = 'No file selected'; @override Component build(BuildContext context) { return FileInput( onFilesSelected: (fileList) { setState(() { if (fileList.isNotEmpty) { _fileName = fileList.first.name; } else { _fileName = 'No file selected'; } }); }, ); return p([text('Selected file: $_fileName')]); } }
// This requires a stateful parent to manage the selected file. FileInput( style: [FileInput.ghost], onFilesSelected: (fileList) { /* handle files */ }, )
Max size 2MB
Fieldset( [ Legend([text('Pick a file')]), FileInput(), FormLabel([text('Max size 2MB')]), ], style: [Size.wFull, Size.maxWxs], )
FileInput(style: [FileInput.xs]), FileInput(style: [FileInput.sm]), FileInput(style: [FileInput.md]), // Default FileInput(style: [FileInput.lg]), FileInput(style: [FileInput.xl]),
FileInput(style: [FileInput.primary]), FileInput(style: [FileInput.secondary]), FileInput(style: [FileInput.accent]), FileInput(style: [FileInput.neutral]), FileInput(style: [FileInput.info]), FileInput(style: [FileInput.success]), FileInput(style: [FileInput.warning]), FileInput(style: [FileInput.error]),
FileInput(disabled: true)