How to sort functionality & filter data got from restapi

Viewed 34

starting my carrer in flutter development for 2 months

while doing this project based in flutter,i get data from rest api with bloc state management & listed it with listvieww builder, but want add sort & filter functionality to it,, can you please explain how to do with an example, excepting valuable suggestions from you guys

search and filter functionilty


class Upcoming extends StatefulWidget {
  Upcoming({Key? key}) : super(key: key);

  @override
  State<Upcoming> createState() => _UpcomingState();
}

class _UpcomingState extends State<Upcoming> {
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<MOdelBloc, MOdelState>(
      builder: (context, state) {
        if (state is MOdelInitial) {
          context.read<MOdelBloc>().add(LoadEVENT());
          return const Center(
            child: CircularProgressIndicator(),
          );
        } else if (state is ModelLoading) {
          return const Center(
            child: CircularProgressIndicator(),
          );
        } else if (state is ModelLoadedstate) {
          return buildupcoming(state.fakestore);
        } else if (state is ErrorSatte) {
          return const Center(
            child: Text('errorstate'),
          );
        }
        return const Center(child: Text('error'));
      },
    );
  }
}

Widget buildupcoming(List<CryptoCurrency> currency) {
  return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.yellow.shade400,
        leading: const Icon(
          Icons.portrait_rounded,
        ),
        title: const Center(
          child: Text(
            'Upcoming Matches',
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
        ),
        actions: const [
          Icon(
            Icons.headset,
          ),
          SizedBox(
            width: 5,
          ),
          Icon(Icons.message)
        ],
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Container(
            height: double.maxFinite,
            margin: const EdgeInsets.all(10),
            child:
                Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                      onPressed: () {}, child: const Text('CRICKET')),
                  const SizedBox(
                    width: 15,
                  ),
                  ElevatedButton(
                      onPressed: () {},
                      child: const Icon(Icons.sports_football))
                ],
              ),
              const SizedBox(
                height: 10,
              ),
              Row(
                children: const [
                  TextWidget(text: 'My Rooms', size: 20),
                  Spacer(),
                  Text(
                    'View all',
                    style: TextStyle(color: Colors.black45),
                  )
                ],
              ),
              const SizedBox(
                height: 5,
              ),
              Container(
                  height: 170,
                  child: PageView.builder(
                      scrollDirection: Axis.horizontal,
                      itemCount: 3,
                      itemBuilder: (context, index) {
                        return Container(
                            margin: const EdgeInsets.only(left: 5),
                            child: Column(children: [
                              SliderCARD(
                                text1: currency[2].fullname.toString(),
                                text2: currency[3].fullname,
                                minitext1: currency[2].price.toString(),
                                minitext2: currency[4].price.toString(),
                                color: Colors.indigo,
                                height: 100,
                              ),
                             Row(children: [IconButton(onPressed: ( ){}, 
               icon: Icon(Icons.arrow_back)),IconButton(onPressed: (){}, icon: Icon(Icons.arrow_back_outlined))],)]));
                      })),
               
              
               
   ListView.builder(
                  physics:const NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  itemCount: currency.length,
                  itemBuilder: (context, index) {
                    final CryptoCurrency cryptoCurrency = currency[index];
                    return Container(
                        margin: const EdgeInsets.only(bottom: 10),
                        height: 100,
                        child: SliderCARD(
                          text1: cryptoCurrency.fullname,
                          text2: currency[3].fullname,
                          minitext1: cryptoCurrency.price.toString(),
                          minitext2: currency[4].price.toString(),
                          color: Colors.white,
                          height: 100,
                        ));
                  })
            ])),
      ));
}
0 Answers
Related