You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.7 KiB
89 lines
2.7 KiB
3 years ago
|
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<LoadGiftRecipient> {
|
||
|
TextEditingController searchkey;
|
||
|
List<TesoUser> recipientMain= <TesoUser>[];
|
||
|
List<TesoUser> 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<UserProvider>(
|
||
|
builder: (context, value, child) {
|
||
|
if (value.friends == null) {
|
||
|
return Center(
|
||
|
child: CircularProgressIndicator(
|
||
|
valueColor: AlwaysStoppedAnimation<Color>(
|
||
|
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)),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
},
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|