Skip to content

Commit cb03fb5

Browse files
committed
Got GraphQL request working!
1 parent 72f788c commit cb03fb5

File tree

8 files changed

+288
-27
lines changed

8 files changed

+288
-27
lines changed

lib/client.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:graphql_flutter/graphql_flutter.dart';
3+
4+
class Config {
5+
static final link = HttpLink(
6+
uri: 'http://10.0.0.213:4000/',
7+
);
8+
9+
static ValueNotifier<GraphQLClient> initializeClient() {
10+
ValueNotifier<GraphQLClient> client = ValueNotifier(
11+
GraphQLClient(
12+
cache: OptimisticCache(dataIdFromObject: typenameDataIdFromObject),
13+
link: link,
14+
),
15+
);
16+
return client;
17+
}
18+
}

lib/main.dart

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
11
import 'package:flutter/material.dart';
22
import 'package:provider/provider.dart';
33

4-
import 'package:arena/providers/tab-provider.dart';
4+
import 'client.dart';
55

6-
// import 'screens/home_screen.dart';
7-
// import 'package:arena/screens/stats_screen.dart';
6+
import 'package:arena/providers/tab-provider.dart';
7+
import 'package:graphql_flutter/graphql_flutter.dart';
88

99
import 'widgets/global/styled_app_bar.dart';
1010
import 'widgets/global/styled_bottom_navigation_bar.dart';
1111

1212
void main() {
13+
WidgetsFlutterBinding.ensureInitialized();
14+
final gq = """query Teams {
15+
teams {
16+
name
17+
logo
18+
}
19+
}""";
20+
1321
runApp(
14-
MaterialApp(
15-
title: 'Arena',
16-
debugShowCheckedModeBanner: false,
17-
home: ChangeNotifierProvider<TabProvider>(
18-
create: (context) => TabProvider(),
19-
builder: (context, child) => Scaffold(
20-
backgroundColor: Colors.grey.shade200,
21-
appBar: StyledAppBar(),
22-
body: context.watch<TabProvider>().screen,
23-
bottomNavigationBar: StyledBottomNavigationBar(),
24-
),
22+
GraphQLProvider(
23+
client: Config.initializeClient(),
24+
child: Query(
25+
builder: (result, {fetchMore, refetch}) {
26+
print(result.loading);
27+
print(result.exception.toString());
28+
print(result.data);
29+
print('end build');
30+
return MaterialApp(
31+
home: Container(
32+
color: Colors.red,
33+
),
34+
);
35+
},
36+
options: QueryOptions(documentNode: gql(gq)),
37+
// child: MaterialApp(
38+
// title: 'Arena',
39+
// debugShowCheckedModeBanner: false,
40+
// home: ChangeNotifierProvider<TabProvider>(
41+
// create: (context) => TabProvider(),
42+
// builder: (context, child) => Scaffold(
43+
// backgroundColor: Colors.grey.shade200,
44+
// appBar: StyledAppBar(),
45+
// body: context.watch<TabProvider>().screen,
46+
// bottomNavigationBar: StyledBottomNavigationBar(),
47+
// ),
48+
// ),
49+
// ),
2550
),
2651
),
2752
);

lib/screens/home_screen.dart

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:graphql_flutter/graphql_flutter.dart';
23

34
import 'package:arena/views/home_screen/noticias_view/noticias.dart';
45
import 'package:arena/views/home_screen/partidos_view/partidos.dart';
@@ -7,18 +8,44 @@ import 'package:arena/views/home_screen/teams_list_view.dart';
78
class HomeScreen extends StatelessWidget {
89
@override
910
Widget build(BuildContext context) {
10-
return SingleChildScrollView(
11-
physics: BouncingScrollPhysics(),
12-
child: Column(
13-
children: [
14-
SizedBox(height: 8),
15-
TeamsListView(),
16-
Partidos(),
17-
Noticias(),
18-
SizedBox(height: 8),
19-
Partidos(),
20-
],
11+
final queryString = '''
12+
query Teams {
13+
teams {
14+
name
15+
logo
16+
}
17+
}
18+
''';
19+
20+
return Query(
21+
options: QueryOptions(
22+
documentNode: gql(queryString),
23+
pollInterval: 1000000000000,
2124
),
25+
builder: (result, {fetchMore, refetch}) {
26+
if (result.hasException) {
27+
print('exception!');
28+
return Container();
29+
}
30+
if (result.loading) {
31+
print('loading!');
32+
return Container();
33+
}
34+
print(result.data);
35+
return SingleChildScrollView(
36+
physics: BouncingScrollPhysics(),
37+
child: Column(
38+
children: [
39+
SizedBox(height: 8),
40+
TeamsListView(),
41+
Partidos(),
42+
Noticias(),
43+
SizedBox(height: 8),
44+
Partidos(),
45+
],
46+
),
47+
);
48+
},
2249
);
2350
}
2451
}

pubspec.lock

Lines changed: 188 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,48 @@ packages:
5757
url: "https://pub.dartlang.org"
5858
source: hosted
5959
version: "1.14.13"
60+
connectivity:
61+
dependency: transitive
62+
description:
63+
name: connectivity
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "0.4.9+2"
67+
connectivity_for_web:
68+
dependency: transitive
69+
description:
70+
name: connectivity_for_web
71+
url: "https://pub.dartlang.org"
72+
source: hosted
73+
version: "0.3.1+2"
74+
connectivity_macos:
75+
dependency: transitive
76+
description:
77+
name: connectivity_macos
78+
url: "https://pub.dartlang.org"
79+
source: hosted
80+
version: "0.1.0+4"
81+
connectivity_platform_interface:
82+
dependency: transitive
83+
description:
84+
name: connectivity_platform_interface
85+
url: "https://pub.dartlang.org"
86+
source: hosted
87+
version: "1.0.6"
88+
convert:
89+
dependency: transitive
90+
description:
91+
name: convert
92+
url: "https://pub.dartlang.org"
93+
source: hosted
94+
version: "2.1.1"
95+
crypto:
96+
dependency: transitive
97+
description:
98+
name: crypto
99+
url: "https://pub.dartlang.org"
100+
source: hosted
101+
version: "2.1.5"
60102
cupertino_icons:
61103
dependency: "direct main"
62104
description:
@@ -71,6 +113,13 @@ packages:
71113
url: "https://pub.dartlang.org"
72114
source: hosted
73115
version: "1.1.0"
116+
file:
117+
dependency: transitive
118+
description:
119+
name: file
120+
url: "https://pub.dartlang.org"
121+
source: hosted
122+
version: "5.2.1"
74123
flutter:
75124
dependency: "direct main"
76125
description: flutter
@@ -81,6 +130,46 @@ packages:
81130
description: flutter
82131
source: sdk
83132
version: "0.0.0"
133+
flutter_web_plugins:
134+
dependency: transitive
135+
description: flutter
136+
source: sdk
137+
version: "0.0.0"
138+
gql:
139+
dependency: transitive
140+
description:
141+
name: gql
142+
url: "https://pub.dartlang.org"
143+
source: hosted
144+
version: "0.12.3"
145+
graphql:
146+
dependency: transitive
147+
description:
148+
name: graphql
149+
url: "https://pub.dartlang.org"
150+
source: hosted
151+
version: "3.1.0"
152+
graphql_flutter:
153+
dependency: "direct main"
154+
description:
155+
name: graphql_flutter
156+
url: "https://pub.dartlang.org"
157+
source: hosted
158+
version: "3.1.0"
159+
http:
160+
dependency: transitive
161+
description:
162+
name: http
163+
url: "https://pub.dartlang.org"
164+
source: hosted
165+
version: "0.12.2"
166+
http_parser:
167+
dependency: transitive
168+
description:
169+
name: http_parser
170+
url: "https://pub.dartlang.org"
171+
source: hosted
172+
version: "3.1.4"
84173
intl:
85174
dependency: transitive
86175
description:
@@ -109,6 +198,13 @@ packages:
109198
url: "https://pub.dartlang.org"
110199
source: hosted
111200
version: "1.1.8"
201+
mime:
202+
dependency: transitive
203+
description:
204+
name: mime
205+
url: "https://pub.dartlang.org"
206+
source: hosted
207+
version: "0.9.7"
112208
nested:
113209
dependency: transitive
114210
description:
@@ -123,13 +219,83 @@ packages:
123219
url: "https://pub.dartlang.org"
124220
source: hosted
125221
version: "1.7.0"
222+
path_provider:
223+
dependency: transitive
224+
description:
225+
name: path_provider
226+
url: "https://pub.dartlang.org"
227+
source: hosted
228+
version: "1.6.14"
229+
path_provider_linux:
230+
dependency: transitive
231+
description:
232+
name: path_provider_linux
233+
url: "https://pub.dartlang.org"
234+
source: hosted
235+
version: "0.0.1+2"
236+
path_provider_macos:
237+
dependency: transitive
238+
description:
239+
name: path_provider_macos
240+
url: "https://pub.dartlang.org"
241+
source: hosted
242+
version: "0.0.4+3"
243+
path_provider_platform_interface:
244+
dependency: transitive
245+
description:
246+
name: path_provider_platform_interface
247+
url: "https://pub.dartlang.org"
248+
source: hosted
249+
version: "1.0.3"
250+
pedantic:
251+
dependency: transitive
252+
description:
253+
name: pedantic
254+
url: "https://pub.dartlang.org"
255+
source: hosted
256+
version: "1.9.0"
257+
platform:
258+
dependency: transitive
259+
description:
260+
name: platform
261+
url: "https://pub.dartlang.org"
262+
source: hosted
263+
version: "2.2.1"
264+
plugin_platform_interface:
265+
dependency: transitive
266+
description:
267+
name: plugin_platform_interface
268+
url: "https://pub.dartlang.org"
269+
source: hosted
270+
version: "1.0.2"
271+
process:
272+
dependency: transitive
273+
description:
274+
name: process
275+
url: "https://pub.dartlang.org"
276+
source: hosted
277+
version: "3.0.13"
126278
provider:
127279
dependency: "direct main"
128280
description:
129281
name: provider
130282
url: "https://pub.dartlang.org"
131283
source: hosted
132284
version: "4.3.2+2"
285+
quiver:
286+
dependency: transitive
287+
description:
288+
name: quiver
289+
url: "https://pub.dartlang.org"
290+
source: hosted
291+
version: "2.1.3"
292+
rxdart:
293+
dependency: transitive
294+
description:
295+
name: rxdart
296+
url: "https://pub.dartlang.org"
297+
source: hosted
298+
version: "0.24.1"
133299
sky_engine:
134300
dependency: transitive
135301
description: flutter
@@ -184,13 +350,34 @@ packages:
184350
url: "https://pub.dartlang.org"
185351
source: hosted
186352
version: "1.2.0"
353+
uuid_enhanced:
354+
dependency: transitive
355+
description:
356+
name: uuid_enhanced
357+
url: "https://pub.dartlang.org"
358+
source: hosted
359+
version: "3.0.2"
187360
vector_math:
188361
dependency: transitive
189362
description:
190363
name: vector_math
191364
url: "https://pub.dartlang.org"
192365
source: hosted
193366
version: "2.0.8"
367+
websocket:
368+
dependency: transitive
369+
description:
370+
name: websocket
371+
url: "https://pub.dartlang.org"
372+
source: hosted
373+
version: "0.0.5"
374+
xdg_directories:
375+
dependency: transitive
376+
description:
377+
name: xdg_directories
378+
url: "https://pub.dartlang.org"
379+
source: hosted
380+
version: "0.1.0"
194381
sdks:
195382
dart: ">=2.9.0-14.0.dev <3.0.0"
196-
flutter: ">=1.16.0"
383+
flutter: ">=1.16.0 <2.0.0"

0 commit comments

Comments
 (0)