srtraj / dropdown_textfield

custom dropdown
MIT License
8 stars 48 forks source link

clearDropDown doesn't reset the clear button #32

Closed Bloddwyn closed 3 months ago

Bloddwyn commented 1 year ago

With controller.clearDropDown() the text gets cleared, but the clear button doesn't reset.

The value 'Test' is selected ResetBefore

Now after the button 'Reset' is clicked the value is set to null, but the clear button doesn't change. ResetAfter

You can test this with this code:

import 'package:dropdown_textfield/dropdown_textfield.dart';
import 'package:flutter/material.dart';

class DropdownTest extends StatefulWidget {
  const DropdownTest({super.key});

  @override
  State<DropdownTest> createState() => DropdownTestState();
}

class DropdownTestState extends State<DropdownTest> {
  final SingleValueDropDownController controller =
      SingleValueDropDownController();
  late List<DropDownValueModel> dropdownItems;

  @override
  void initState() {
    super.initState();

    //Items
    dropdownItems = List<DropDownValueModel>.empty(growable: true);
    dropdownItems.add(const DropDownValueModel(name: 'Test', value: 'Test'));
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      DropDownTextField(
        controller: controller,
        textFieldDecoration: const InputDecoration(
          labelText: 'Test',
        ),
        clearOption: true,
        dropDownItemCount: 1,
        dropDownList: dropdownItems,
      ),
      TextButton(
          onPressed: () =>setState(() {
            controller.clearDropDown();
          }),
          child: const Text('Reset'))
    ]);
  }
}
Bloddwyn commented 1 year ago

Okay I think I found the problem. In line 442 you should use clearFun(); instead of _cnt.clear();

srtraj commented 3 months ago

Sorry @Bloddwyn , I was busy with other things and couldn't maintain this package. Fixed this issue Please check the latest release dropdown_textfield: ^1.1.0