UploadListCore class

A widget to easily display and manage uploads and their current state.

Usage:

class ComposeScreen extends StatefulWidget {
  const ComposeScreen({Key? key}) : super(key: key);

  @override
  State<ComposeScreen> createState() => _ComposeScreenState();
}

class _ComposeScreenState extends State<ComposeScreen> {
  @override
  Widget build(BuildContext context) {
    final uploadController = FeedProvider.of(context).bloc.uploadController;
    return Scaffold(
      appBar: AppBar(title: const Text('Compose'), actions: [
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: ActionChip(
            label: const Text(
              'Post',
              style: TextStyle(
                color: Colors.blue,
              ),
            ),
            backgroundColor: Colors.white,
            onPressed: () {
              final attachments = uploadController.getMediaUris();
              for (var element in attachments) {
                print(element.uri);
              }
              uploadController.clear();
            },
          ),
        )
      ]),
      body: SingleChildScrollView(
        child: Column(
          children: [
            const Padding(
              padding: EdgeInsets.all(8.0),
              child: TextField(
                decoration: InputDecoration(hintText: 'enter a description'),
              ),
            ),
            IconButton(
              onPressed: () async {
                final ImagePicker _picker = ImagePicker();
                final XFile? image =
                    await _picker.pickImage(source: ImageSource.gallery);

                if (image != null) {
                  await uploadController
                      .uploadImage(AttachmentFile(path: image.path));
                } else {
                  // User canceled the picker
                }
              },
              icon: const Icon(Icons.file_copy),
            ),
            UploadListCore(
              uploadController: uploadController,
              loadingBuilder: (context) => CircularProgressIndicator(),
              uploadsErrorBuilder: (error) =>
                  Text('Could not upload error'),
              uploadsBuilder: (context, uploads) {
                return SizedBox(
                  height: 100,
                  child: ListView.builder(
                    scrollDirection: Axis.horizontal,
                    itemCount: uploads.length,
                    itemBuilder: (context, index) => FileUploadStateWidget(
                        fileState: uploads[index],
                        onRemoveUpload: (attachment) {
                          return uploadController.removeUpload(attachment);
                        },
                        onCancelUpload: (attachment) {
                          uploadController.cancelUpload(attachment);
                        },
                        onRetryUpload: (attachment) async {
                          return uploadController.uploadImage(attachment);
                        }),
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}
Inheritance

Constructors

UploadListCore({Key? key, required UploadController uploadController, required UploadsBuilder uploadsBuilder, required UploadsErrorBuilder uploadsErrorBuilder, required WidgetBuilder loadingBuilder})
A widget to easily display and manage uploads and their current state.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingBuilder WidgetBuilder
Builder used to build a loading widget
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
uploadController UploadController
The upload controller used to manage uploads.
final
uploadsBuilder → UploadsBuilder
Builder that will be called with a list of current uploads and their state.
final
uploadsErrorBuilder → UploadsErrorBuilder
An error builder to show when an error occurs.
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
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.
override
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