1+ import 'dart:convert' ;
2+
3+ import 'package:flutter/material.dart' ;
4+ import 'package:github_following/Models/User.dart' ;
5+ import 'package:github_following/Requests/GithubRequest.dart' ;
6+ import 'package:provider/provider.dart' ;
7+ import 'package:github_following/Providers/UserProvider.dart' ;
8+
9+ class FollowingPage extends StatefulWidget {
10+ @override
11+ _FollowingPageState createState () => _FollowingPageState ();
12+ }
13+
14+ class _FollowingPageState extends State <FollowingPage > {
15+ User user;
16+ List <User > users;
17+
18+ @override
19+ Widget build (BuildContext context) {
20+ setState (() {
21+ user = Provider .of <UserProvider >(context).getUSer ();
22+
23+ Github (user.login).fetchFollowing ().then ((following) {
24+ Iterable list = json.decode (following.body);
25+ setState (() {
26+ users = list.map ((model) => User .fromJson (model)).toList ();
27+ });
28+ });
29+ });
30+
31+ return Scaffold (
32+ body: Container (
33+ color: Colors .white,
34+ child: CustomScrollView (
35+ slivers: < Widget > [
36+ SliverAppBar (
37+ brightness: Brightness .light,
38+ leading: IconButton (
39+ icon: Icon (Icons .arrow_back_ios, color: Colors .grey,), onPressed: () {
40+ Navigator .pop (context);
41+ },
42+ ),
43+ backgroundColor: Colors .white,
44+ expandedHeight: 200 ,
45+ flexibleSpace: FlexibleSpaceBar (
46+ collapseMode: CollapseMode .pin,
47+ background: Container (
48+ child: Column (
49+ mainAxisAlignment: MainAxisAlignment .end,
50+ children: < Widget > [
51+ Container (
52+ width: 100 ,
53+ height: 100 ,
54+ child: CircleAvatar (
55+ radius: 50.0 ,
56+ backgroundColor: Colors .transparent,
57+ backgroundImage: NetworkImage (user.avatar_url),
58+ ),
59+ ),
60+ SizedBox (height: 20 ,),
61+ Text (user.login, style: TextStyle (fontSize: 20 ),)
62+ ],
63+ ),
64+ ),
65+ ),
66+ ),
67+ SliverList (
68+ delegate: SliverChildListDelegate ([
69+ Container (
70+ height: 600 ,
71+ child:
72+ users != null ?
73+ ListView .builder (
74+ scrollDirection: Axis .vertical,
75+ itemCount: users.length,
76+ itemBuilder: (context, index) {
77+ return Container (
78+ padding: EdgeInsets .all (15 ),
79+ decoration: BoxDecoration (
80+ border: Border (bottom: BorderSide (color: Colors .grey[200 ]))
81+ ),
82+ child: Row (
83+ crossAxisAlignment: CrossAxisAlignment .center,
84+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
85+ children: < Widget > [
86+ Row (
87+ crossAxisAlignment: CrossAxisAlignment .center,
88+ children: < Widget > [
89+ Container (
90+ width: 60 ,
91+ height: 60 ,
92+ child: CircleAvatar (
93+ backgroundImage: NetworkImage (users[index].avatar_url),
94+ ),
95+ ),
96+ SizedBox (width: 10 ,),
97+ Text (users[index].login, style: TextStyle (fontSize: 20 , color: Colors .grey[700 ]),),
98+ ],
99+ ),
100+ Text ('Following' , style: TextStyle (color: Colors .blue),)
101+ ],
102+ ),
103+ );
104+ },
105+ ) :
106+ Container (child: Align (child: Text ('Data is loading ...' ))),
107+ )
108+ ]),
109+ )
110+ ],
111+ ),
112+ ),
113+ );
114+ }
115+ }
0 commit comments