Scott Vickrey
 · Visioneering (Old Antennas still in Ø)

Custom Widget Compiler - Unknown Error

Hello, can someone tell me why this custom widget code fails to compile with an "Unknown Error"?

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

class ReorderList extends StatefulWidget {
  const ReorderList(
      {Key? key,
      this.width,
      this.height,
      required this.documents,
      required this.fillColor,
      required this.borderColor,
      required this.dragColor})
      : super(key: key);

  final double? width;
  final double? height;
  final List<DocumentSnapshot> documents;
  final Color fillColor;
  final Color borderColor;
  final Color dragColor;

  @override
  _ReorderListState createState() => _ReorderListState();
}

class _ReorderListState extends State<ReorderList> {
  late List<DocumentSnapshot> _items;

  @override
  void initState() {
    super.initState();
    _items = widget.documents;
  }

  @override
  Widget build(BuildContext context) {
    return ReorderableListView(
      proxyDecorator: proxyDecorator,
      padding: const EdgeInsets.symmetric(horizontal: 40),
      children: <Widget>[
        for (int index = 0; index < _items.length; index++)
          Padding(
            key: Key('$index'),
            padding: EdgeInsetsDirectional.fromSTEB(6, 6, 6, 6),
            child: Container(
              width: double.infinity,
              height: 80,
              decoration: BoxDecoration(
                color: widget.fillColor,
                borderRadius: BorderRadius.circular(10),
                border: Border.all(color: widget.borderColor),
              ),
              child: Align(
                alignment: AlignmentDirectional(0, 0),
                child: Text(_items[index]['name'],
                    style: FlutterFlowTheme.of(context).bodyText1),
              ),
            ),
          ),
      ],
      onReorder: (int oldIndex, int newIndex) {
        setState(() {
          if (oldIndex < newIndex) {
            newIndex -= 1;
          }
          final DocumentSnapshot item = _items.removeAt(oldIndex);
          _items.insert(newIndex, item);
          updateFirestoreDocuments();
        });
      },
    );
  }

  void updateFirestoreDocuments() async {
    for (int i = 0; i < _items.length; i++) {
      await FirebaseFirestore.instance
          .collection('habits')
          .doc(_items[i].id)
          .update({'ordinalPos': i});
    }
  }

  Widget proxyDecorator(Widget child, int index, Animation<double> animation) {
    return AnimatedBuilder(
      animation: animation,
      builder: (BuildContext context, Widget? child) {
        final double animValue = Curves.easeInOut.transform(animation.value);
        final double elevation = lerpDouble(0, 6, animValue)!;
        return Material(
          elevation: elevation,
          color: Color(0x00000000),
          shadowColor: widget.dragColor,
          child: child,
        );
      },
      child: child,
    );
  }
}
1
2 replies