import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:job_app/config/palette.dart'; import 'package:job_app/models/APiResponse.dart'; import 'package:job_app/models/Country/country.dart'; import 'package:job_app/models/Country/country_paginator.dart'; import 'package:job_app/services/countries_service.dart'; import 'package:job_app/singletons/country.dart'; import 'package:provider/provider.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; class CountryDropDown extends StatefulWidget { final bool isCountryValid; final changeCountry; CountryDropDown({Key key ,this.isCountryValid,this.changeCountry}) : super(key: key); @override _CountryDropDownState createState() => _CountryDropDownState(); } class _CountryDropDownState extends State { List countries=[]; String hintText='Country'; int pageNumber = 0 ; int currentPage; int totalItems; int totalPages; RefreshController _refreshController = RefreshController(initialRefresh: false); CountriesService _countriesService=CountriesService(); Future getCountries()async{ ApiResponseModel response =await _countriesService.getCountries(size: 10,page: pageNumber); countrySingleTons.countries= response.data.countries; currentPage=response.data.currentPage; totalItems=response.data.totalItems; totalPages=response.data.totalItems; } void _onRefresh() async { // monitor network fetch await Future.delayed(Duration(milliseconds: 1000)); // if failed,use refreshFailed() _refreshController.refreshCompleted(); } void _onLoading() async { if(pageNumber[ PopupMenuItem( enabled: false, child: Container( width: 120, height: 110, child: ChangeNotifierProvider.value( value: CountrySingleTons(), child: Consumer( builder: (context,data,child){ return SmartRefresher( controller: _refreshController, onRefresh: _onRefresh, onLoading: _onLoading, enablePullDown: false, enablePullUp: true, footer: CustomFooter( builder: (BuildContext context, LoadStatus mode) { Widget body; if (mode == LoadStatus.loading) { body = CupertinoActivityIndicator .partiallyRevealed(); } return Container( height: 50.0, child: Center(child: body), ); }, ), child: data.countries.isNotEmpty?ListView.builder( itemCount: data.countries.length, shrinkWrap: true, physics: BouncingScrollPhysics(), itemBuilder: (context,index)=>Padding( padding: const EdgeInsets.all(8.0), child: GestureDetector( onTap: (){ setState(() { hintText=data.countries[index].name.toString(); }); this.widget.changeCountry(data.countries[index].name,index); Navigator.pop(context); }, child: Text(data.countries[index].name,style: TextStyle( color: Palette.hintText, fontSize: 16 ),), ), ), ): Text("Loading"), ); }, ), ), ), ), ], ), ); } }