Skip to content

Commit bbdc1f4

Browse files
committed
migrate example apps to null safety
1 parent 61beb0d commit bbdc1f4

File tree

5 files changed

+18
-43
lines changed

5 files changed

+18
-43
lines changed

example/flutter_app/lib/main.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import 'package:logging/logging.dart';
21
import 'package:flutter/material.dart';
2+
import 'package:logging/logging.dart';
33
import 'package:phoenix_socket/phoenix_socket.dart';
44

55
void main() {
@@ -41,7 +41,7 @@ class MyApp extends StatelessWidget {
4141
}
4242

4343
class MyHomePage extends StatefulWidget {
44-
MyHomePage({Key key, this.title}) : super(key: key);
44+
MyHomePage({Key? key, required this.title}) : super(key: key);
4545

4646
// This widget is the home page of your application. It is stateful, meaning
4747
// that it has a State object (defined below) that contains fields that affect
@@ -61,8 +61,8 @@ class MyHomePage extends StatefulWidget {
6161
class _MyHomePageState extends State<MyHomePage> {
6262
int _counter = 0;
6363
bool _connected = false;
64-
PhoenixSocket _socket;
65-
PhoenixChannel _channel;
64+
late PhoenixSocket _socket;
65+
PhoenixChannel? _channel;
6666

6767
_MyHomePageState() {
6868
_socket = PhoenixSocket('ws://localhost:4001/socket/websocket')..connect();
@@ -72,7 +72,7 @@ class _MyHomePageState extends State<MyHomePage> {
7272
_socket.openStream.listen((event) {
7373
setState(() {
7474
_channel = _socket.addChannel(topic: 'channel3');
75-
return _connected = true;
75+
_connected = true;
7676
});
7777
});
7878
}
@@ -100,7 +100,9 @@ class _MyHomePageState extends State<MyHomePage> {
100100
appBar: AppBar(
101101
// Here we take the value from the MyHomePage object that was created by
102102
// the App.build method, and use it to set our appbar title.
103-
title: Text(_connected ? "Connected" : "Disconnected"),
103+
title: Text(
104+
_channel != null && _connected ? "Connected" : "Disconnected",
105+
),
104106
),
105107
body: Center(
106108
// Center is a layout widget. It takes a single child and positions it

example/flutter_app/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1818
version: 1.0.0+1
1919

2020
environment:
21-
sdk: ">=2.7.0 <3.0.0"
21+
sdk: '>=2.12.0 <3.0.0'
2222

2323
dependencies:
2424
flutter:
@@ -29,7 +29,7 @@ dependencies:
2929

3030
# The following adds the Cupertino Icons font to your application.
3131
# Use with the CupertinoIcons class for iOS style icons.
32-
cupertino_icons: ^1.0.0
32+
cupertino_icons: ^1.0.2
3333

3434
dev_dependencies:
3535
flutter_test:

example/flutter_app/test/widget_test.dart

Lines changed: 0 additions & 30 deletions
This file was deleted.

example/simple/lib/main.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ void main() async {
1313
channel1.push('ping', {'from': uuid});
1414

1515
await for (var message in channel1.messages) {
16-
if (message.event != 'pong' || message.payload['from'] == uuid) continue;
17-
print("received ${message.event} from ${message.payload['from']}");
18-
Timer(Duration(seconds: 1), () {
16+
if (message.event != PhoenixChannelEvent.custom('pong') ||
17+
message.payload?['from'] == uuid) continue;
18+
print("received ${message.event} from ${message.payload!['from']}");
19+
Timer(const Duration(seconds: 1), () {
1920
channel1.push('ping', {'from': uuid});
2021
});
2122
}

example/simple/pubspec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ name: phoenix_socket_example
22
description: A PhoenixSocket example
33
version: 0.0.2
44
homepage: https://www.github.com/matehat/phoenix-socket-dart
5+
publish_to: none
56

67
environment:
7-
sdk: ">=2.3.0 <3.0.0"
8+
sdk: ">=2.12.0 <3.0.0"
89

910
dependencies:
1011
phoenix_socket:
1112
path: ../../
12-
uuid: ^2.0.4
13+
14+
uuid: ^3.0.1
1315

1416
dev_dependencies: {}

0 commit comments

Comments
 (0)