简体   繁体   中英

Show dropdown boundary if focused

I am making an android TV app using Flutter. How to show the boundary on a dropdown widget if the dropdown is focused?

I tried wrapping the dropdown with focus but then I could not access dropdown items.

Focus(
      focusNode: _focusNode,
      child: Container(
        decoration: _focusNode.hasFocus
            ? BoxDecoration(border: Border.all(color: Colors.grey))
            : BoxDecoration(),
        child: DropdownButtonHideUnderline(
          child: DropdownButton<Country>(
            icon: const Icon(
              Icons.keyboard_arrow_down,
              color: Color(0xFF707B89),
              size: 18.0,
            ),
            isDense: true,
            onChanged: (Country value) {
              setState(() {
                _selectedCountry = value;
                widget.onValuePicked(value);
              });
            },
            items: items,
            value: _selectedCountry,
          ),
        ),
      ),
    ),

You can use DropdownButtonFormField with OutlineInputBorder on decoration .

   final border = OutlineInputBorder(
      borderSide: BorderSide(color: Colors.yellow),
      borderRadius: BorderRadius.circular(8),
    );
DropdownButtonFormField<Country?>(
  decoration: InputDecoration(
    border: border,
    focusedBorder: border, //this is the one you are looking for,
    enabledBorder: border,
    errorBorder: border,
    disabledBorder: border,
    focusedErrorBorder: border,
  ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM