Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Container(
- height: 70.0,
- child: Row(
- children: <Widget>[
- Flexible(
- flex: 1,
- child: Padding(
- padding: const EdgeInsets.only(left: 8.0),
- child: TextField(
- controller: _searchController,
- textAlign: TextAlign.start,
- keyboardType: TextInputType.text),
- textInputAction: TextInputAction.send,),
- ),
- ),
- InkWell(
- child: Container(
- height: 40.0,
- width: 40.0,
- child: Icon(Icons.send, size: 25.0, color: Colors.black),
- ),
- onTap:_search,
- ),
- ],
- ),
- ),
- Expanded(
- child: FutureBuilder(
- future: _searchPost(),
- builder: (context, snapshot) {
- if(snapshot.hasData) {
- List<Contents> content = snapshot.data;
- ListView.separated(
- itemBuilder: (context, index) {
- return ListTile(
- title: Text(content[index].title),
- ),
- subtitle: Text(content[index].createdAt),
- ),
- );
- },
- itemCount: content.length,
- separatorBuilder: (context, index) {
- return Divider(height: 1.0);
- },
- );
- }else if (snapshot.hasError){
- print('error);
- }
- return Center(
- child: CircularProgressIndicator(
- valueColor: AlwaysStoppedAnimation(Colors.blue),
- ),
- );
- }),
- )
- Future<List<Contents>> _searchPost() async {
- final response = await http.get('${Constants.searchPosts}${_searchController.text}').timeout(Duration(seconds: 1));
- if(response.statusCode == 200){
- final responseString = json.decode(response.body) as List;
- List<Contents> res= responseString.map((j)=>Contents.fromJson(j)).toList();
- print(json.decode(response.body));//<-- work fine and show result in console
- return res;
- }else{
- return null;
- }
- }
- void _search() {
- if (_searchController.text.length <= 0) {
- }else{
- _searchPost();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement