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 { TextEditingController searchkey; List friendsMain = []; List friends; SharedPreferences prefs; void clearText() { setState(() { searchkey.clear(); }); } @override void initState() { searchkey = new TextEditingController(); super.initState(); } updateList(String name) { setState(() { friends = friendsMain .where((element) => element.username.toLowerCase().contains(name.toLowerCase())) .toList(); friends.sort((a, b) { return b.firstname.compareTo(a.firstname); }); }); } @override Widget build(BuildContext context) { return Scaffold( // extendBody: true, appBar: PreferredSize( preferredSize: Size.fromHeight(90), child: 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 (friendsMain.length == 0) { friendsMain = value.friends; friends = value.friends; } friends.sort((a, b) { return b.firstname.compareTo(a.firstname); }); 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)), ); }, ); } }, ), ); } }