// ignore_for_file: unnecessary_null_comparison import 'package:provider/provider.dart'; import 'package:teso/Classes/TesoUser.dart'; import 'package:teso/Pages/PageWidgets/Friends/friendTile.dart'; import 'package:teso/Pages/PageWidgets/Inbox/newMessageHeader.dart'; import 'package:flutter/material.dart'; import 'package:teso/Pages/PageWidgets/Friends/header.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:teso/providers/user_provider.dart'; class LoadGiftRecipient extends StatefulWidget { @override _LoadGiftRecipientState createState() => _LoadGiftRecipientState(); } class _LoadGiftRecipientState extends State { TextEditingController? searchkey; List recipientMain= []; List? recipient; SharedPreferences? prefs; void clearText() { setState(() {}); } @override void initState() { searchkey = new TextEditingController(); super.initState(); } updateList(String name, recipientMain) { setState(() { recipient = recipientMain .where((element) => element.username.toLowerCase().contains(name.toLowerCase())) .toList(); recipient!.sort((a, b) { return b.firstname!.compareTo(a.firstname!); }); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(150), child: Container( // margin: EdgeInsets.only(top: 30), child: Column(children: [ buildNewHead(context, clearText, "Look up recipient"), buildFriendsHeader(context, searchkey, updateList), ]), ), ), body: Consumer( builder: (context, value, child) { if (value.friends == null) { return Center( child: CircularProgressIndicator( valueColor: AlwaysStoppedAnimation( Theme.of(context).primaryColor), ), ); } else { if (recipientMain.length == 0) { recipientMain = value.friends; recipient = value.friends; } recipient!.sort((a, b) { return b.firstname!.compareTo(a.firstname!); }); return ListView.builder( itemCount: recipient!.length, itemBuilder: (context, int index) { return InkWell( onTap: () => Navigator.pop(context, recipient!.elementAt(index)), child: buildFriend(context, recipient!.elementAt(index)), ); }, ); } }, ), ); } }