Skip to content

Commit

Permalink
feat(flutter_bloc)!: nullsafety (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Mar 4, 2021
1 parent 4c6fde2 commit 7edfd53
Show file tree
Hide file tree
Showing 83 changed files with 504 additions and 588 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/flutter_bloc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: subosito/[email protected]
with:
channel: beta
- name: Install Dependencies
run: flutter packages get
- name: Format
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/flutter_examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: subosito/[email protected]
with:
channel: beta
- name: Install Dependencies
working-directory: ${{ matrix.folder }}
run: flutter packages get
Expand All @@ -85,7 +87,7 @@ jobs:
working-directory: ${{ matrix.folder }}
run: |
if [ -d "test" ]; then
flutter test --no-pub --test-randomize-ordering-seed random
flutter test --no-pub --test-randomize-ordering-seed random --no-sound-null-safety
fi
build:
needs: [examples]
Expand Down
4 changes: 2 additions & 2 deletions docs/_snippets/flutter_todos_tutorial/filtered_todos.dart.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FilteredTodos extends StatelessWidget {
todo: todo,
onDismissed: (direction) {
BlocProvider.of<TodosBloc>(context).add(TodoDeleted(todo));
Scaffold.of(context).showSnackBar(DeleteTodoSnackBar(
ScaffoldMessenger.of(context).showSnackBar(DeleteTodoSnackBar(
key: ArchSampleKeys.snackbar,
todo: todo,
onUndo: () =>
Expand All @@ -46,7 +46,7 @@ class FilteredTodos extends StatelessWidget {
}),
);
if (removedTodo != null) {
Scaffold.of(context).showSnackBar(DeleteTodoSnackBar(
ScaffoldMessenger.of(context).showSnackBar(DeleteTodoSnackBar(
key: ArchSampleKeys.snackbar,
todo: todo,
onUndo: () => BlocProvider.of<TodosBloc>(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TickerBloc extends Bloc<TickerEvent, TickerState> {
TickerBloc(this._ticker) : super(TickerInitial());

final Ticker _ticker;
StreamSubscription _subscription;
StreamSubscription? _subscription;

@override
Stream<TickerState> mapEventToState(TickerEvent event) async* {
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_bloc_with_stream/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() {
/// {@endtemplate}
class TickerApp extends MaterialApp {
/// {@macro ticker_app}
TickerApp({Key key})
TickerApp({Key? key})
: super(
key: key,
home: BlocProvider(
Expand Down
6 changes: 3 additions & 3 deletions examples/flutter_bloc_with_stream/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: flutter_bloc_with_stream
description: A new Flutter project.

version: 1.0.0+1
publish_to: none

environment:
sdk: ">=2.6.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"

dependencies:
flutter:
sdk: flutter
flutter_bloc:
path: ../../packages/flutter_bloc
equatable: ^1.2.5
equatable: ^2.0.0-nullsafety.0

flutter:
uses-material-design: true
3 changes: 1 addition & 2 deletions examples/flutter_complex_list/lib/list/cubit/list_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_complex_list/list/list.dart';
import 'package:flutter_complex_list/repository.dart';
import 'package:meta/meta.dart';
import 'package:pedantic/pedantic.dart';

part 'list_state.dart';

class ListCubit extends Cubit<ListState> {
ListCubit({@required this.repository}) : super(const ListState.loading());
ListCubit({required this.repository}) : super(const ListState.loading());

final Repository repository;

Expand Down
11 changes: 3 additions & 8 deletions examples/flutter_complex_list/lib/list/models/item.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import 'package:meta/meta.dart';
import 'package:equatable/equatable.dart';

class Item extends Equatable {
const Item({
@required this.id,
@required this.value,
required this.id,
required this.value,
this.isDeleting = false,
});

final String id;
final String value;
final bool isDeleting;

Item copyWith({
String id,
String value,
bool isDeleting,
}) {
Item copyWith({String? id, String? value, bool? isDeleting}) {
return Item(
id: id ?? this.id,
value: value ?? this.value,
Expand Down
8 changes: 4 additions & 4 deletions examples/flutter_complex_list/lib/list/view/list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ListPage extends StatelessWidget {
}

class _ListView extends StatelessWidget {
const _ListView({Key key, this.items}) : super(key: key);
const _ListView({Key? key, required this.items}) : super(key: key);

final List<Item> items;

Expand All @@ -48,9 +48,9 @@ class _ListView extends StatelessWidget {

class _ItemTile extends StatelessWidget {
const _ItemTile({
Key key,
@required this.item,
@required this.onDeletePressed,
Key? key,
required this.item,
required this.onDeletePressed,
}) : super(key: key);

final Item item;
Expand Down
8 changes: 4 additions & 4 deletions examples/flutter_complex_list/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: flutter_complex_list
description: A new Flutter project.

version: 1.0.0+1
publish_to: none

environment:
sdk: ">=2.6.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"

dependencies:
flutter:
sdk: flutter
flutter_bloc:
path: ../../packages/flutter_bloc
equatable: ^1.2.5
pedantic: ^1.9.0
equatable: ^2.0.0-nullsafety.0
pedantic: ^1.10.0-nullsafety.3

flutter:
uses-material-design: true
1 change: 1 addition & 0 deletions examples/flutter_counter/integration_test/app_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:integration_test/integration_test.dart';
import 'package:flutter_counter/main.dart' as app;

Expand Down
1 change: 1 addition & 0 deletions examples/flutter_counter/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions examples/flutter_counter/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
2 changes: 0 additions & 2 deletions examples/flutter_counter/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../Flutter/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/integration_test/integration_test.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/integration_test.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down

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

2 changes: 1 addition & 1 deletion examples/flutter_counter/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import 'counter/counter.dart';
/// {@endtemplate}
class CounterApp extends MaterialApp {
/// {@macro counter_app}
const CounterApp({Key key}) : super(key: key, home: const CounterPage());
const CounterApp({Key? key}) : super(key: key, home: const CounterPage());
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'counter_view.dart';
/// {@endtemplate}
class CounterPage extends StatelessWidget {
/// {@macro counter_page}
const CounterPage({Key key}) : super(key: key);
const CounterPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand Down
18 changes: 12 additions & 6 deletions examples/flutter_counter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
name: flutter_counter
description: A new Flutter project.

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1
publish_to: none

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"

dependencies:
flutter:
sdk: flutter
bloc: ^6.1.0
flutter_bloc: ^6.1.0
bloc:
path: ../../packages/bloc
flutter_bloc:
path: ../../packages/flutter_bloc

dependency_overrides:
bloc:
path: ../../packages/bloc
flutter_bloc:
path: ../../packages/flutter_bloc

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore: import_of_legacy_library_into_null_safe
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_counter/counter/counter.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// ignore: import_of_legacy_library_into_null_safe
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_counter/counter/counter.dart';
import 'package:flutter_counter/counter/view/counter_view.dart';
import 'package:flutter_test/flutter_test.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:mockito/mockito.dart';

class MockCounterCubit extends MockBloc<int> implements CounterCubit {}
Expand All @@ -12,11 +14,12 @@ const _incrementButtonKey = Key('counterView_increment_floatingActionButton');
const _decrementButtonKey = Key('counterView_decrement_floatingActionButton');

void main() {
CounterCubit counterCubit;
late CounterCubit counterCubit;

setUp(() {
counterCubit = MockCounterCubit();
when(counterCubit.state).thenReturn(0);
whenListen(counterCubit, Stream.value(0));
});

group('CounterView', () {
Expand Down Expand Up @@ -55,7 +58,9 @@ void main() {
),
),
);
await tester.tap(find.byKey(_decrementButtonKey));
final decrementFinder = find.byKey(_decrementButtonKey);
await tester.ensureVisible(decrementFinder);
await tester.tap(decrementFinder);
verify(counterCubit.decrement()).called(1);
});
});
Expand Down
1 change: 1 addition & 0 deletions examples/flutter_counter/test_driver/integration_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore: import_of_legacy_library_into_null_safe
import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
2 changes: 1 addition & 1 deletion examples/flutter_dynamic_form/lib/bloc/new_car_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ part 'new_car_event.dart';
part 'new_car_state.dart';

class NewCarBloc extends Bloc<NewCarEvent, NewCarState> {
NewCarBloc({NewCarRepository newCarRepository})
NewCarBloc({required NewCarRepository newCarRepository})
: _newCarRepository = newCarRepository,
super(NewCarState.initial());

Expand Down
6 changes: 3 additions & 3 deletions examples/flutter_dynamic_form/lib/bloc/new_car_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class NewCarFormLoaded extends NewCarEvent {}
class NewCarBrandChanged extends NewCarEvent {
const NewCarBrandChanged({this.brand});

final String brand;
final String? brand;
}

class NewCarModelChanged extends NewCarEvent {
const NewCarModelChanged({this.model});

final String model;
final String? model;
}

class NewCarYearChanged extends NewCarEvent {
const NewCarYearChanged({this.year});

final String year;
final String? year;
}
Loading

0 comments on commit 7edfd53

Please sign in to comment.