WebFileSelector class

Enables selecting files on the web platform.

Example:

@override
Widget build(BuildContext context) {
  // ...

  Widget button = ElevatedButton(
    onPressed: () {
      if (!WebFileSelector.isIOSWeb) {
        // Not iOS/iPadOS on the web platform
        // Use file_selector or file_picker package to select files
      }
    },
    child: const Text('Select Files'),
  );

  if (WebFileSelector.isIOSWeb) {
    // iOS/iPadOS on the web platform

    // Wrap the original button with WebFileSelector widget
    button = WebFileSelector(
      onData: (files) async {
        // Received files from the web browser
        for (final XFile file in files) {
          debugPrint('${file.name} (MIME type: ${file.mimeType})');

          // You can get bytes from the file with these methods:
          final Uint8List bytes = await file.readAsBytes();
          final Stream<Uint8List> stream = file.openRead();
          // ...
        }
      },
      // The "accept" argument accepts the same value as the accept attribute in <input type="file">
      // Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept
      accept: '.pdf, .png, .jpg, .jpeg, .tif, .tiff',
      multiple: true,
      child: button,
    );
  }

  return Scaffold(body: Center(child: button));
}
Inheritance

Constructors

WebFileSelector({Key? key, required void onData(List<XFile> files)?, required Widget child, String? accept, bool? multiple})
Creates a new instance of the WebFileSelector class
const

Properties

accept String?
Accepts the same value as the accept attribute in <input type="file">.
final
child Widget
A child widget
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
multiple bool?
Whether to let users select multiple files or not.
final
onData → (void Function(List<XFile> files)?)
A callback function that is called when user selects files
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<WebFileSelector>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

isIOSWeb bool
Tells whether the code is running on a web browser on iOS/iPadOS.
final