Skip to content

Commit 6ebba8e

Browse files
authored
Merge pull request #39 from cal-pratt/deprecate-new
Remove the use of new throughout the project
2 parents f668ada + a08abfc commit 6ebba8e

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
@@ -48,10 +48,10 @@ To use the client it first needs to be initialized with an endpoint and cache. I
4848
import 'package:graphql_flutter/graphql_flutter.dart';
4949
5050
void main() {
51-
ValueNotifier<Client> client = new ValueNotifier(
52-
new Client(
51+
ValueNotifier<Client> client = ValueNotifier(
52+
Client(
5353
endPoint: 'https://api.github.com/graphql',
54-
cache: new InMemoryCache(),
54+
cache: InMemoryCache(),
5555
apiToken: '<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>',
5656
),
5757
);
@@ -69,9 +69,9 @@ In order to use the client, you app needs to be wrapped with the `GraphqlProvide
6969
```dart
7070
...
7171
72-
return new GraphqlProvider(
72+
return GraphqlProvider(
7373
client: client,
74-
child: new MaterialApp(
74+
child: MaterialApp(
7575
title: 'Flutter Demo',
7676
...
7777
),
@@ -106,7 +106,7 @@ In your widget:
106106
```dart
107107
...
108108
109-
new Query(
109+
Query(
110110
readRepositories, // this is the query you just created
111111
variables: {
112112
'nRepositories': 50,
@@ -118,22 +118,22 @@ new Query(
118118
String error,
119119
}) {
120120
if (error != '') {
121-
return new Text(error);
121+
return Text(error);
122122
}
123123
124124
if (loading) {
125-
return new Text('Loading');
125+
return Text('Loading');
126126
}
127127
128128
// it can be either Map or List
129129
List repositories = data['viewer']['repositories']['nodes'];
130130
131-
return new ListView.builder(
131+
return ListView.builder(
132132
itemCount: repositories.length,
133133
itemBuilder: (context, index) {
134134
final repository = repositories[index];
135135
136-
return new Text(repository['name']);
136+
return Text(repository['name']);
137137
});
138138
},
139139
);
@@ -163,20 +163,20 @@ The syntax for mutations is fairly similar to that of a query. The only diffence
163163
```dart
164164
...
165165
166-
new Mutation(
166+
Mutation(
167167
addStar,
168168
builder: (
169169
runMutation, { // you can name it whatever you like
170170
bool loading,
171171
var data,
172172
String error,
173173
}) {
174-
return new FloatingActionButton(
174+
return FloatingActionButton(
175175
onPressed: () => runMutation({
176176
'starrableId': <A_STARTABLE_REPOSITORY_ID>,
177177
}),
178178
tooltip: 'Star',
179-
child: new Icon(Icons.star),
179+
child: Icon(Icons.star),
180180
);
181181
},
182182
onCompleted: (Map<String, dynamic> data) {
@@ -208,12 +208,12 @@ You can always access the client direcly from the `GraphqlProvider` but to make
208208
```dart
209209
...
210210
211-
return new GraphqlConsumer(
211+
return GraphqlConsumer(
212212
builder: (Client client) {
213213
// do something with the client
214214
215-
return new Container(
216-
child: new Text('Hello world'),
215+
return Container(
216+
child: Text('Hello world'),
217217
);
218218
},
219219
);
@@ -233,10 +233,10 @@ The in-memory cache can automatically be saved to and restored from offline stor
233233
class MyApp extends StatelessWidget {
234234
@override
235235
Widget build(BuildContext context) {
236-
return new GraphqlProvider(
236+
return GraphqlProvider(
237237
client: client,
238-
child: new CacheProvider(
239-
child: new MaterialApp(
238+
child: CacheProvider(
239+
child: MaterialApp(
240240
title: 'Flutter Demo',
241241
...
242242
),

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)