Skip to content

Commit 94206d4

Browse files
committed
2 parents 1f2e289 + 6ebba8e commit 94206d4

File tree

8 files changed

+56
-56
lines changed

8 files changed

+56
-56
lines changed

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ To use the client it first needs to be initialized with an endpoint and cache. I
6060
import 'package:graphql_flutter/graphql_flutter.dart';
6161
6262
void main() {
63-
ValueNotifier<Client> client = new ValueNotifier(
64-
new Client(
63+
ValueNotifier<Client> client = ValueNotifier(
64+
Client(
6565
endPoint: 'https://api.github.com/graphql',
66-
cache: new InMemoryCache(),
66+
cache: InMemoryCache(),
6767
apiToken: '<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>',
6868
),
6969
);
@@ -81,9 +81,9 @@ In order to use the client, you app needs to be wrapped with the `GraphqlProvide
8181
```dart
8282
...
8383
84-
return new GraphqlProvider(
84+
return GraphqlProvider(
8585
client: client,
86-
child: new MaterialApp(
86+
child: MaterialApp(
8787
title: 'Flutter Demo',
8888
...
8989
),
@@ -118,7 +118,7 @@ In your widget:
118118
```dart
119119
...
120120
121-
new Query(
121+
Query(
122122
readRepositories, // this is the query you just created
123123
variables: {
124124
'nRepositories': 50,
@@ -130,22 +130,22 @@ new Query(
130130
String error,
131131
}) {
132132
if (error != '') {
133-
return new Text(error);
133+
return Text(error);
134134
}
135135
136136
if (loading) {
137-
return new Text('Loading');
137+
return Text('Loading');
138138
}
139139
140140
// it can be either Map or List
141141
List repositories = data['viewer']['repositories']['nodes'];
142142
143-
return new ListView.builder(
143+
return ListView.builder(
144144
itemCount: repositories.length,
145145
itemBuilder: (context, index) {
146146
final repository = repositories[index];
147147
148-
return new Text(repository['name']);
148+
return Text(repository['name']);
149149
});
150150
},
151151
);
@@ -175,20 +175,20 @@ The syntax for mutations is fairly similar to that of a query. The only diffence
175175
```dart
176176
...
177177
178-
new Mutation(
178+
Mutation(
179179
addStar,
180180
builder: (
181181
runMutation, { // you can name it whatever you like
182182
bool loading,
183183
var data,
184184
String error,
185185
}) {
186-
return new FloatingActionButton(
186+
return FloatingActionButton(
187187
onPressed: () => runMutation({
188188
'starrableId': <A_STARTABLE_REPOSITORY_ID>,
189189
}),
190190
tooltip: 'Star',
191-
child: new Icon(Icons.star),
191+
child: Icon(Icons.star),
192192
);
193193
},
194194
onCompleted: (Map<String, dynamic> data) {
@@ -278,12 +278,12 @@ You can always access the client direcly from the `GraphqlProvider` but to make
278278
```dart
279279
...
280280
281-
return new GraphqlConsumer(
281+
return GraphqlConsumer(
282282
builder: (Client client) {
283283
// do something with the client
284284
285-
return new Container(
286-
child: new Text('Hello world'),
285+
return Container(
286+
child: Text('Hello world'),
287287
);
288288
},
289289
);
@@ -303,10 +303,10 @@ The in-memory cache can automatically be saved to and restored from offline stor
303303
class MyApp extends StatelessWidget {
304304
@override
305305
Widget build(BuildContext context) {
306-
return new GraphqlProvider(
306+
return GraphqlProvider(
307307
client: client,
308-
child: new CacheProvider(
309-
child: new MaterialApp(
308+
child: CacheProvider(
309+
child: MaterialApp(
310310
title: 'Flutter Demo',
311311
...
312312
),

example/lib/main.dart

+20-20
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ import 'package:graphql_flutter/graphql_flutter.dart';
44
import './queries/readRepositories.dart' as queries;
55
import './mutations/addStar.dart' as mutations;
66

7-
void main() => runApp(new MyApp());
7+
void main() => runApp(MyApp());
88

99
class MyApp extends StatelessWidget {
1010
@override
1111
Widget build(BuildContext context) {
12-
ValueNotifier<Client> client = new ValueNotifier(
13-
new Client(
12+
ValueNotifier<Client> client = ValueNotifier(
13+
Client(
1414
endPoint: 'https://api.github.com/graphql',
15-
cache: new InMemoryCache(),
15+
cache: InMemoryCache(),
1616
apiToken: '<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>',
1717
),
1818
);
1919

20-
return new GraphqlProvider(
20+
return GraphqlProvider(
2121
client: client,
22-
child: new CacheProvider(
23-
child: new MaterialApp(
22+
child: CacheProvider(
23+
child: MaterialApp(
2424
title: 'Flutter Demo',
25-
theme: new ThemeData(
25+
theme: ThemeData(
2626
primarySwatch: Colors.blue,
2727
),
28-
home: new MyHomePage(title: 'Flutter Demo Home Page'),
28+
home: MyHomePage(title: 'Flutter Demo Home Page'),
2929
),
3030
),
3131
);
@@ -41,17 +41,17 @@ class MyHomePage extends StatefulWidget {
4141
final String title;
4242

4343
@override
44-
_MyHomePageState createState() => new _MyHomePageState();
44+
_MyHomePageState createState() => _MyHomePageState();
4545
}
4646

4747
class _MyHomePageState extends State<MyHomePage> {
4848
@override
4949
Widget build(BuildContext context) {
50-
return new Scaffold(
51-
appBar: new AppBar(
52-
title: new Text(widget.title),
50+
return Scaffold(
51+
appBar: AppBar(
52+
title: Text(widget.title),
5353
),
54-
body: new Query(
54+
body: Query(
5555
queries.readRepositories,
5656
pollInterval: 1,
5757
builder: ({
@@ -60,22 +60,22 @@ class _MyHomePageState extends State<MyHomePage> {
6060
String error,
6161
}) {
6262
if (error != '') {
63-
return new Text(error);
63+
return Text(error);
6464
}
6565

6666
if (loading) {
67-
return new Text('Loading');
67+
return Text('Loading');
6868
}
6969

7070
// it can be either Map or List
7171
List repositories = data['viewer']['repositories']['nodes'];
7272

73-
return new ListView.builder(
73+
return ListView.builder(
7474
itemCount: repositories.length,
7575
itemBuilder: (context, index) {
7676
final repository = repositories[index];
7777

78-
return new Mutation(
78+
return Mutation(
7979
mutations.addStar,
8080
builder: (
8181
addStar, {
@@ -88,11 +88,11 @@ class _MyHomePageState extends State<MyHomePage> {
8888
data['addStar']['starrable']['viewerHasStarred'];
8989
}
9090

91-
return new ListTile(
91+
return ListTile(
9292
leading: repository['viewerHasStarred']
9393
? const Icon(Icons.star, color: Colors.amber)
9494
: const Icon(Icons.star_border),
95-
title: new Text(repository['name']),
95+
title: Text(repository['name']),
9696
// NOTE: optimistic ui updates are not implemented yet, therefore changes may take upto 1 second to show.
9797
onTap: () {
9898
addStar({

lib/src/cache/in_memory.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:io';
66
import 'package:path_provider/path_provider.dart';
77

88
class InMemoryCache {
9-
HashMap<String, dynamic> _inMemoryCache = new HashMap<String, dynamic>();
9+
HashMap<String, dynamic> _inMemoryCache = HashMap<String, dynamic>();
1010

1111
Future<String> get _localStoragePath async {
1212
final Directory directory = await getApplicationDocumentsDirectory();
@@ -37,15 +37,15 @@ class InMemoryCache {
3737
try {
3838
final File file = await _localStorageFile;
3939
final HashMap<String, dynamic> storedHashMap =
40-
new HashMap<String, dynamic>();
40+
HashMap<String, dynamic>();
4141

4242
if (file.existsSync()) {
4343
Stream<dynamic> inputStream = file.openRead();
4444

4545
inputStream
4646
.transform(utf8.decoder) // Decode bytes to UTF8.
4747
.transform(
48-
new LineSplitter()) // Convert stream to individual lines.
48+
LineSplitter()) // Convert stream to individual lines.
4949
.listen((String line) {
5050
final List keyAndValue = json.decode(line);
5151

@@ -57,12 +57,12 @@ class InMemoryCache {
5757
} on FileSystemException {
5858
// TODO: handle No such file
5959

60-
return new HashMap<String, dynamic>();
60+
return HashMap<String, dynamic>();
6161
} catch (error) {
6262
// TODO: handle error
6363
print(error);
6464

65-
return new HashMap<String, dynamic>();
65+
return HashMap<String, dynamic>();
6666
}
6767
}
6868

lib/src/client.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Client {
1717
this.endPoint = endPoint;
1818
this.cache = cache;
1919
this.apiToken = apiToken;
20-
this.client = new http.Client();
20+
this.client = http.Client();
2121
}
2222

2323
String _endpoint;
@@ -67,15 +67,15 @@ class Client {
6767
final String reasonPhrase = response.reasonPhrase;
6868

6969
if (statusCode < 200 || statusCode >= 400) {
70-
throw new http.ClientException(
70+
throw http.ClientException(
7171
'Network Error: $statusCode $reasonPhrase',
7272
);
7373
}
7474

7575
final Map<String, dynamic> jsonResponse = json.decode(response.body);
7676

7777
if (jsonResponse['errors'] != null && jsonResponse['errors'].length > 0) {
78-
throw new Exception(
78+
throw Exception(
7979
'Error returned by the server in the query' +
8080
jsonResponse['errors'].toString(),
8181
);
@@ -124,7 +124,7 @@ class Client {
124124
if (cache.hasEntity(body)) {
125125
return cache.read(body);
126126
} else {
127-
throw new Exception('Can\'t find field in cache.');
127+
throw Exception('Can\'t find field in cache.');
128128
}
129129
}
130130
}

lib/src/widgets/cache_provider.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class CacheProvider extends StatefulWidget {
1212
final Widget child;
1313

1414
@override
15-
_CacheProviderState createState() => new _CacheProviderState();
15+
_CacheProviderState createState() => _CacheProviderState();
1616
}
1717

1818
class _CacheProviderState extends State<CacheProvider>

lib/src/widgets/graphql_provider.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class GraphqlProvider extends StatefulWidget {
2020
}
2121

2222
@override
23-
State<StatefulWidget> createState() => new _GraphqlProviderState();
23+
State<StatefulWidget> createState() => _GraphqlProviderState();
2424
}
2525

2626
class _GraphqlProviderState extends State<GraphqlProvider> {
@@ -42,7 +42,7 @@ class _GraphqlProviderState extends State<GraphqlProvider> {
4242

4343
@override
4444
Widget build(BuildContext context) {
45-
return new _InheritedGraphqlProvider(
45+
return _InheritedGraphqlProvider(
4646
client: widget.client,
4747
child: widget.child,
4848
);

lib/src/widgets/mutation.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Mutation extends StatefulWidget {
2525
final OnMutationCompleted onCompleted;
2626

2727
@override
28-
MutationState createState() => new MutationState();
28+
MutationState createState() => MutationState();
2929
}
3030

3131
class MutationState extends State<Mutation> {

lib/src/widgets/query.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Query extends StatefulWidget {
2525
final int pollInterval;
2626

2727
@override
28-
QueryState createState() => new QueryState();
28+
QueryState createState() => QueryState();
2929
}
3030

3131
class QueryState extends State<Query> {
@@ -36,14 +36,14 @@ class QueryState extends State<Query> {
3636
bool initialFetch = true;
3737
Duration pollInterval;
3838
Timer pollTimer;
39-
Map currentVariables = new Map();
39+
Map currentVariables = Map();
4040

4141
@override
4242
void initState() {
4343
super.initState();
4444

4545
if (widget.pollInterval is int) {
46-
pollInterval = new Duration(seconds: widget.pollInterval);
46+
pollInterval = Duration(seconds: widget.pollInterval);
4747
}
4848

4949
getQueryResult();
@@ -107,7 +107,7 @@ class QueryState extends State<Query> {
107107
}
108108

109109
if (pollInterval is Duration && !(pollTimer is Timer)) {
110-
pollTimer = new Timer.periodic(
110+
pollTimer = Timer.periodic(
111111
pollInterval,
112112
(Timer t) => getQueryResult(),
113113
);

0 commit comments

Comments
 (0)