Skip to content

Commit

Permalink
Merge pull request #381 from GetStream/feature/null-safety
Browse files Browse the repository at this point in the history
feat: migrate to NNBD(non-nullable by default)
  • Loading branch information
imtoori authored May 3, 2021
2 parents 01b664b + 7bc1f96 commit 7be4f9e
Show file tree
Hide file tree
Showing 275 changed files with 124,894 additions and 9,614 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/stream_flutter_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
./.github/workflows/scripts/install-tools.sh
flutter pub global activate tuneup
- name: 'Bootstrap Workspace'
run: melos bootstrap
run: melos bootstrap --verbose
- name: 'Dart Analyze'
run: |
melos exec -c 3 --ignore="*example*" -- \
Expand All @@ -50,7 +50,7 @@ jobs:
run: |
./.github/workflows/scripts/install-tools.sh
- name: 'Bootstrap Workspace'
run: melos bootstrap
run: melos bootstrap --verbose
- name: 'Dart'
run: |
melos exec -c 1 -- \
Expand All @@ -72,7 +72,7 @@ jobs:
flutter pub global activate coverage
flutter pub global activate remove_from_coverage
- name: 'Bootstrap Workspace'
run: melos bootstrap
run: melos bootstrap --verbose
- name: 'Dart Test'
run: |
cd packages/stream_chat
Expand Down
3 changes: 1 addition & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ dev_dependencies:
pedantic: 1.9.2

environment:
sdk: ">=2.7.0 <3.0.0"
flutter: ">=1.22.4 <2.0.0"
sdk: ">=2.12.0 <3.0.0"
5 changes: 5 additions & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0-nullsafety.0

- Migrate this package to null safety
- Added typed filters

## 1.5.3

- fix: `StreamChatClient.connect` returns quicker when you're using the persistence package
Expand Down
1 change: 0 additions & 1 deletion packages/stream_chat/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ analyzer:
- lib/**/*.g.dart
- lib/**/*.freezed.dart
- example/*
- test/*
linter:
rules:
- always_use_package_imports
Expand Down
3 changes: 1 addition & 2 deletions packages/stream_chat/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ targets:
json_serializable:
options:
explicit_to_json: true
field_rename: snake
any_map: true
field_rename: snake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 35 additions & 33 deletions packages/stream_chat/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';

Future<void> main() async {
/// Create a new instance of [StreamChatClient] passing the apikey obtained from your
/// project dashboard.
final client = StreamChatClient(
'b67pax5b2wdq',
logLevel: Level.INFO,
);
/// Create a new instance of [StreamChatClient]
/// by passing the apikey obtained from your project dashboard.
final client = StreamChatClient('b67pax5b2wdq', logLevel: Level.INFO);

/// Set the current user. In a production scenario, this should be done using
/// a backend to generate a user token using our server SDK.
Expand All @@ -21,7 +18,7 @@ Future<void> main() async {
'https://getstream.io/random_png/?id=cool-shadow-7&amp;name=Cool+shadow',
},
),
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiY29vbC1zaGFkb3ctNyJ9.gkOlCRb1qgy4joHPaxFwPOdXcGvSPvp6QY0S4mpRkVo',
'''eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiY29vbC1zaGFkb3ctNyJ9.gkOlCRb1qgy4joHPaxFwPOdXcGvSPvp6QY0S4mpRkVo''',
);

/// Creates a channel using the type `messaging` and `godevs`.
Expand All @@ -44,15 +41,16 @@ Future<void> main() async {

/// Example using Stream's Low Level Dart client.
class StreamExample extends StatelessWidget {
/// To initialize this example, an instance of [client] and [channel] is required.
/// To initialize this example, an instance of
/// [client] and [channel] is required.
const StreamExample({
Key key,
@required this.client,
@required this.channel,
Key? key,
required this.client,
required this.channel,
}) : super(key: key);

/// Instance of [StreamChatClient] we created earlier. This contains information about
/// our application and connection state.
/// Instance of [StreamChatClient] we created earlier.
/// This contains information about our application and connection state.
final StreamChatClient client;

/// The channel we'd like to observe and participate.
Expand All @@ -71,28 +69,31 @@ class StreamExample extends StatelessWidget {
/// containing the channel name and a [MessageView] displaying recent messages.
class HomeScreen extends StatelessWidget {
/// [HomeScreen] is constructed using the [Channel] we defined earlier.
const HomeScreen({Key key, @required this.channel}) : super(key: key);
const HomeScreen({
Key? key,
required this.channel,
}) : super(key: key);

/// Channel object containing the [Channel.id] we'd like to observe.
final Channel channel;

@override
Widget build(BuildContext context) {
final messages = channel.state.channelStateStream;
final messages = channel.state!.channelStateStream;
return Scaffold(
appBar: AppBar(
title: Text('Channel: ${channel.id}'),
),
body: SafeArea(
child: StreamBuilder<ChannelState>(
child: StreamBuilder<ChannelState?>(
stream: messages,
builder: (
BuildContext context,
AsyncSnapshot<ChannelState> snapshot,
AsyncSnapshot<ChannelState?> snapshot,
) {
if (snapshot.hasData && snapshot.data != null) {
return MessageView(
messages: snapshot.data.messages.reversed.toList(),
messages: snapshot.data!.messages.reversed.toList(),
channel: channel,
);
} else if (snapshot.hasError) {
Expand All @@ -104,8 +105,8 @@ class HomeScreen extends StatelessWidget {
}
return const Center(
child: SizedBox(
width: 100.0,
height: 100.0,
width: 100,
height: 100,
child: CircularProgressIndicator(),
),
);
Expand All @@ -121,9 +122,9 @@ class HomeScreen extends StatelessWidget {
class MessageView extends StatefulWidget {
/// Message takes the latest list of messages and the current channel.
const MessageView({
Key key,
@required this.messages,
@required this.channel,
Key? key,
required this.messages,
required this.channel,
}) : super(key: key);

/// List of messages sent in the given channel.
Expand All @@ -137,8 +138,8 @@ class MessageView extends StatefulWidget {
}

class _MessageViewState extends State<MessageView> {
TextEditingController _controller;
ScrollController _scrollController;
late final TextEditingController _controller;
late final ScrollController _scrollController;

List<Message> get _messages => widget.messages;

Expand Down Expand Up @@ -176,28 +177,28 @@ class _MessageViewState extends State<MessageView> {
reverse: true,
itemBuilder: (BuildContext context, int index) {
final item = _messages[index];
if (item.user.id == widget.channel.client.uid) {
if (item.user?.id == widget.channel.client.uid) {
return Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(item.text),
padding: const EdgeInsets.all(8),
child: Text(item.text ?? ''),
),
);
} else {
return Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(item.text),
padding: const EdgeInsets.all(8),
child: Text(item.text ?? ''),
),
);
}
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
child: Row(
children: [
Expanded(
Expand Down Expand Up @@ -245,7 +246,8 @@ class _MessageViewState extends State<MessageView> {
}
}

/// Helper extension for quickly retrieving the current user id from a [StreamChatClient].
/// Helper extension for quickly retrieving
/// the current user id from a [StreamChatClient].
extension on StreamChatClient {
String get uid => state.user.id;
String get uid => state.user!.id;
}
11 changes: 6 additions & 5 deletions packages/stream_chat/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
name: example
description: A new Flutter project.

publish_to: 'none'
publish_to: "none"
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
cupertino_icons: ^1.0.0
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
stream_chat:
stream_chat:
path: ../

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
uses-material-design: true
Loading

0 comments on commit 7be4f9e

Please sign in to comment.