Open azhengyongqin opened 4 years ago
Use it in the following way... After modifying the preselectedValue in other positions, the selected value of the component remains unchanged
preselectedValue
import 'package:flutter/material.dart'; import 'package:searchable_dropdown/searchable_dropdown.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), home: DemoPage(), ); } } class DemoPage extends StatefulWidget { @override _DemoPageState createState() => _DemoPageState(); } class _DemoPageState extends State<DemoPage> { String preselectedValue = "dolor sit"; List<String> items = [ "dolor sit", "sit", "dolor", ]; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: SearchableDropdown.single( isExpanded: true, value: preselectedValue, items: items .map( (e) => DropdownMenuItem( child: Text(e), value: e, ), ) .toList(), onChanged: (value) { setState(() { preselectedValue = value; }); }, ), ); } } i fix the code for show the dolor sit, make sure the item is on the value dropitem...
_Originally posted by @rekiyagami in https://github.com/icemanbsi/searchable_dropdown/issues/85#issuecomment-660204493_
because the value "preselectValue" is ref to "dolor sit" u need too make sure the value is null or place it in InitState() :D
String preselectedValue ;
or
IniState(){ String preselectedValue = "dolor sit"; }
Use it in the following way... After modifying the
preselectedValue
in other positions, the selected value of the component remains unchanged_Originally posted by @rekiyagami in https://github.com/icemanbsi/searchable_dropdown/issues/85#issuecomment-660204493_