ListTile Components displacing when used with Dismissible Widget - Flutter

28 Views Asked by At

ListTile components are displaing whenever it is not being dragged to the full extent for Dismissal. Please look at the photos to understand the bug better

enter image description here enter image description here enter image description here

code for home_view.dart:

class HomeView extends StatefulWidget {
  const HomeView({Key? key}) : super(key: key);
  static const String id = '/';

  @override
  State<HomeView> createState() => _HomeViewState();
}

class _HomeViewState extends State<HomeView> {
  @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return Scaffold(
      appBar: AppBar(
        title: Text(
          Constants.riders,
          style: TextStyle(
            fontSize: SizeConfig.blockSizeVertical * 2.5,
            // fontWeight: FontWeight.bold,
          ),
        ),
        elevation: 0,
      ),
      body: Padding(
        padding: EdgeInsets.symmetric(
            horizontal: SizeConfig.blockSizeHorizontal * 4),
        child: Consumer<HomeViewModel>(
            builder: (_, model, __) => model.riders.isNotEmpty
                ? ListView.builder(
                    itemBuilder: (_, index) => Padding(
                      padding: EdgeInsets.only(
                          top: SizeConfig.blockSizeVertical * 2),
                      child: Dismissible(
                          key: UniqueKey(),
                          onDismissed: (direction) {
                            model.removeRider(model.riders[index]);
                            if (direction == DismissDirection.startToEnd) {
                              showSuccessSnackbar(
                                  Constants.approveRider, context);
                            } else {
                              showErrorSnackbar(Constants.rejectRider, context);
                            }
                          },
                          background: Container(
                            color: Colors.green,
                            child: Align(
                              alignment: Alignment.centerLeft,
                              child: Padding(
                                padding: EdgeInsets.only(
                                    left: SizeConfig.blockSizeHorizontal * 2),
                                child: Text(
                                  Constants.approve,
                                  style: bodyTextStyle3,
                                ),
                              ),
                            ),
                          ),
                          secondaryBackground: Container(
                            color: Colors.red,
                            child: Align(
                              alignment: Alignment.centerRight,
                              child: Padding(
                                padding: EdgeInsets.only(
                                    right: SizeConfig.blockSizeHorizontal * 2),
                                child: Text(
                                  Constants.reject,
                                  style: bodyTextStyle3,
                                ),
                              ),
                            ),
                          ),
                          child: RiderTile(rider: model.riders[index])),
                    ),
                    itemCount: model.riders.length,
                  )
                : Center(
                    child: Text(
                      Constants.noRiders,
                      style: bodyTextStyle1,
                    ),
                  )),
      ),
      floatingActionButton: RectangularFAB(
        text: Constants.add,
        onPress: () {
          Navigator.of(context).pushNamed(AddRiderView.id);
        },
      ),
    );
  }
}

code for RiderTile:

 @override
  Widget build(BuildContext context) {
    return ListTile(
      onTap: () {
        Navigator.of(context).pushNamed(RiderView.id, arguments: widget.rider);
      },
      leading: widget.rider.photo == null
          ? const CircleAvatar(backgroundImage: AssetImage('assets/rider.png'))
          : CircleAvatar(
              backgroundImage: FileImage(widget.rider.photo!),
            ),
      shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(2)),
          side: BorderSide(color: Colors.grey)),
      title: Text(widget.rider.name, style: bodyTextStyle1),
      subtitle: Text(widget.rider.phone),
    );

Can someone please help me understand as to why such an error is occurring and how I can fix it?

0

There are 0 best solutions below