I used a package to add dropdown with search feature unfortunately it doesn't search my json data
i managed to load my json to the dropdown, the only issue is it cant search my local json file i
should i remove the dependency altogether and create my own custom dropdown widget or change the dependency code and make it search i don't know which path is easier, as this dependency i could not change it to make it search my local json
Help will be much appreciated
I created a small simple app to demonstrate the dropdown with my local json
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:searchable_dropdown/searchable_dropdown.dart';
void main() => runApp(SearchableDropdownApp());
class SearchableDropdownApp extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<SearchableDropdownApp> {
Map<String, String> selectedValueMap = Map();
List<Map> _areas;
@override
void initState() {
selectedValueMap["local"] = null;
super.initState();
loadLocalJsonData();
}
@override
Widget build(BuildContext context) {
final items = _areas.map((county) {
return DropdownMenuItem<String>(
child: Text(county["name"].toString()),
);
}).toList();
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Searchable Dropdown Example App'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text('Dropdown with local data : ',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold
),
),
),
SearchableDropdown(
items: items,
value: selectedValueMap["local"],
isCaseSensitiveSearch: false,
hint: Text('Select County'),
searchHint: Text('Counties'),
onChanged: (value) {
setState(() {
selectedValueMap["local"] = value;
});
},
),
],
),
),
);
}
Future loadLocalJsonData() async {
String jsonCounties = await rootBundle.loadString("assets/counties.json");
setState(() {
_areas = List<Map>.from(jsonDecode(jsonCounties) as List);
});
}
}
question from:
https://stackoverflow.com/questions/65892470/how-to-search-dropdown-with-data-from-a-local-json 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…