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.

92 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/Sub_Pages/userProfile3P.dart';
import 'package:flutter/material.dart';
import 'package:teso/Pages/PageWidgets/Friends/header.dart';
import 'package:page_transition/page_transition.dart';
import 'package:teso/providers/user_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Friends extends StatefulWidget {
@override
_FriendsState createState() => _FriendsState();
}
class _FriendsState extends State<Friends> {
TextEditingController? searchkey;
3 years ago
List<TesoUser> friendsMain = <TesoUser>[];
late List<TesoUser> friends;
SharedPreferences? prefs;
3 years ago
void clearText() {
setState(() {
searchkey!.clear();
3 years ago
});
}
@override
void initState() {
searchkey = new TextEditingController();
super.initState();
}
updateList(String name) {
setState(() {
friends = friendsMain
.where((element) =>
element.username!.toLowerCase().contains(name.toLowerCase()))
3 years ago
.toList();
friends.sort((a, b) {
return b.firstname!.compareTo(a.firstname!);
3 years ago
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
// extendBody: true,
appBar: PreferredSize(
preferredSize: Size.fromHeight(90),
child: buildFriendsHeader(context, searchkey, updateList),
),
body: Consumer<UserProvider>(
builder: (context, value, child) {
if (value.friends.isEmpty) {
3 years ago
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).primaryColor)));
} else {
if (friendsMain.length == 0) {
friendsMain = value.friends;
friends = value.friends;
}
friends.sort((a, b) {
return b.firstname!.compareTo(a.firstname!);
3 years ago
});
return ListView.builder(
itemCount: friends.length,
itemBuilder: (context, int index) {
return InkWell(
onTap: () => Navigator.push(
context,
PageTransition(
child: UserProfileThirdPerson(
user: friends.elementAt(index),
),
type: PageTransitionType.fade,
),
),
child: buildFriend(context, friends.elementAt(index)),
);
},
);
}
},
),
);
}
}