11import 'package:flutter/material.dart' ;
2+ import 'package:graphql_flutter/graphql_flutter.dart' ;
23
34class UsersPage extends StatefulWidget {
45 const UsersPage ({Key ? key}) : super (key: key);
@@ -8,53 +9,77 @@ class UsersPage extends StatefulWidget {
89}
910
1011class _UsersPageState extends State <UsersPage > {
12+ List users = [];
13+ final String _query = """
14+ query{
15+ users{
16+ name
17+ id
18+ profession
19+ age
20+ }
21+ }
22+ """ ;
23+
1124 @override
1225 Widget build (BuildContext context) {
13- return ListView .builder (
14- itemCount: 10 ,
15- itemBuilder: (context, index) {
16- return Stack (
17- children: [
18- Container (
19- margin: const EdgeInsets .only (bottom: 23.0 , left: 10.0 , right: 10.0 ),
20- decoration: BoxDecoration (
21- color: Colors .white,
22- borderRadius: BorderRadius .circular (15.0 ),
23- boxShadow: [
24- BoxShadow (
25- offset: const Offset (0.0 , 10.0 ),
26- color: Colors .grey.shade300,
27- blurRadius: 30.0 ,
28- )
29- ],
30- ),
31- padding: const EdgeInsets .all (20 ),
32- child: InkWell (
33- // ignore: avoid_unnecessary_containers
34- child: Container (
35- child: Column (
36- crossAxisAlignment: CrossAxisAlignment .start,
37- mainAxisSize: MainAxisSize .min,
38- children: [
39- Row (
40- mainAxisAlignment: MainAxisAlignment .spaceBetween,
41- children: const [
42- Text (
43- 'Hello' ,
44- style: TextStyle (
45- fontSize: 16.0 ,
46- fontWeight: FontWeight .bold,
26+ return Query (
27+ options: QueryOptions (document: gql (_query)),
28+ builder: (result, {fetchMore, refetch}) {
29+ if (result.isLoading){
30+ return const CircularProgressIndicator ();
31+ }
32+ users = result.data! ["users" ];
33+
34+ return ListView .builder (
35+ itemCount: users.length,
36+ itemBuilder: (context, index) {
37+ final user = users[index];
38+
39+ return Stack (
40+ children: [
41+ Container (
42+ margin: const EdgeInsets .only (bottom: 23.0 , left: 10.0 , right: 10.0 ),
43+ decoration: BoxDecoration (
44+ color: Colors .white,
45+ borderRadius: BorderRadius .circular (15.0 ),
46+ boxShadow: [
47+ BoxShadow (
48+ offset: const Offset (0.0 , 10.0 ),
49+ color: Colors .grey.shade300,
50+ blurRadius: 30.0 ,
51+ )
52+ ],
53+ ),
54+ padding: const EdgeInsets .all (20 ),
55+ child: InkWell (
56+ // ignore: avoid_unnecessary_containers
57+ child: Container (
58+ child: Column (
59+ crossAxisAlignment: CrossAxisAlignment .start,
60+ mainAxisSize: MainAxisSize .min,
61+ children: [
62+ Row (
63+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
64+ children: [
65+ Text (
66+ '${user ["name" ]}' ,
67+ style: const TextStyle (
68+ fontSize: 16.0 ,
69+ fontWeight: FontWeight .bold,
70+ ),
4771 ),
48- ) ,
49- ] ,
50- ) ,
51- ] ,
72+ ] ,
73+ ) ,
74+ ] ,
75+ ) ,
5276 ),
5377 ),
5478 ),
55- ),
56- ],
57- );
79+ ],
80+ );
81+ },
82+ );
5883 },
5984 );
6085 }
0 commit comments