Skip to content

Commit b069d14

Browse files
committed
update deps and fix lints
1 parent dfb60b9 commit b069d14

12 files changed

+433
-290
lines changed

analysis_options.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
include: package:flutter_lints/flutter.yaml
22
analyzer:
3-
strong-mode:
4-
implicit-casts: false
5-
implicit-dynamic: false
3+
language:
4+
strict-casts: true
5+
strict-raw-types: true
66
linter:
77
rules:
88
- public_member_api_docs

example/lib/bloc_with_deps.dart

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// ignore_for_file: avoid_print
2-
31
import 'dart:async';
42

3+
import 'package:disposebag/disposebag.dart';
4+
import 'package:flutter/foundation.dart';
55
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
66
import 'package:rxdart_ext/rxdart_ext.dart';
77

@@ -11,14 +11,14 @@ class Dependencies {
1111
var _i = 0;
1212

1313
Dependencies() {
14-
print('$this::init');
14+
debugPrint('$this::init');
1515
}
1616

1717
Future<String> loadSomething() =>
1818
Future.delayed(const Duration(milliseconds: 500), () => 'String ${_i++}');
1919

2020
void dispose() {
21-
print('$this::dispose');
21+
debugPrint('$this::dispose');
2222
}
2323
}
2424

@@ -34,21 +34,15 @@ class Bloc1 extends DisposeCallbackBaseBloc {
3434
}) : super(dispose);
3535

3636
factory Bloc1(Dependencies dependencies) {
37-
// ignore: close_sinks
3837
final loadS = StreamController<void>();
3938

4039
final string$ = loadS.stream
4140
.switchMap((value) => Rx.fromCallable(dependencies.loadSomething))
4241
.cast<String?>()
4342
.publishState(null);
44-
final connection = string$.connect();
4543

4644
return Bloc1._(
47-
dispose: () async {
48-
await connection.cancel();
49-
await loadS.close();
50-
print('Bloc1::disposed');
51-
},
45+
dispose: DisposeBag([loadS, string$.connect()]).dispose,
5246
load: () => loadS.add(null),
5347
string$: string$,
5448
);
@@ -57,11 +51,11 @@ class Bloc1 extends DisposeCallbackBaseBloc {
5751

5852
class Bloc2 implements BaseBloc {
5953
Bloc2(CounterBloc bloc) {
60-
print('$this::init with counter bloc $bloc');
54+
debugPrint('$this::init with counter bloc $bloc');
6155
}
6256

6357
@override
6458
void dispose() {
65-
print('$this::dispose');
59+
debugPrint('$this::dispose');
6660
}
6761
}

example/lib/counter_bloc.dart

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// ignore_for_file: avoid_print
2-
31
import 'dart:async';
42

3+
import 'package:disposebag/disposebag.dart';
54
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
65
import 'package:rxdart_ext/rxdart_ext.dart';
76

@@ -19,22 +18,16 @@ class CounterBloc extends DisposeCallbackBaseBloc {
1918
}) : super(dispose);
2019

2120
factory CounterBloc() {
22-
// ignore: close_sinks
2321
final incrementController = StreamController<void>();
2422

25-
final state = incrementController.stream
23+
final state$ = incrementController.stream
2624
.scan<int>((acc, _, __) => acc + 1, 0)
2725
.publishState(0);
28-
final connection = state.connect();
2926

3027
return CounterBloc._(
31-
dispose: () async {
32-
await connection.cancel();
33-
await incrementController.close();
34-
print('CounterBloc::disposed');
35-
},
36-
increment: () => incrementController.add(null),
37-
state: state,
28+
dispose: DisposeBag([incrementController, state$.connect()]).dispose,
29+
increment: incrementController.addNull,
30+
state: state$,
3831
);
3932
}
4033
}

example/lib/main.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void main() {
1212
}
1313

1414
class MyApp extends StatelessWidget {
15-
const MyApp({Key? key}) : super(key: key);
15+
const MyApp({super.key});
1616

1717
@override
1818
Widget build(BuildContext context) {
@@ -29,7 +29,7 @@ class MyApp extends StatelessWidget {
2929
}
3030

3131
class StartPage extends StatelessWidget {
32-
const StartPage({Key? key}) : super(key: key);
32+
const StartPage({super.key});
3333

3434
@override
3535
Widget build(BuildContext context) {
@@ -62,7 +62,7 @@ class StartPage extends StatelessWidget {
6262
}
6363

6464
class MyHomePage extends StatefulWidget {
65-
const MyHomePage({Key? key}) : super(key: key);
65+
const MyHomePage({super.key});
6666

6767
@override
6868
State<MyHomePage> createState() => _MyHomePageState();
@@ -80,12 +80,12 @@ class _MyHomePageState extends State<MyHomePage> {
8080
mainAxisAlignment: MainAxisAlignment.center,
8181
children: <Widget>[
8282
const Text('You have pushed the button this many times:'),
83-
const SizedBox(height: 8),
83+
const SizedBox(height: 16),
8484
const TextCounter1(),
8585
const TextCounter2(),
86-
const SizedBox(height: 8),
86+
const SizedBox(height: 16),
8787
const TextBloc1(),
88-
const SizedBox(height: 8),
88+
const SizedBox(height: 16),
8989
ElevatedButton(
9090
onPressed: () => context.bloc<Bloc2>(),
9191
child: const Text('Access Bloc 2'),
@@ -99,7 +99,7 @@ class _MyHomePageState extends State<MyHomePage> {
9999
}
100100

101101
class TextCounter1 extends StatelessWidget {
102-
const TextCounter1({Key? key}) : super(key: key);
102+
const TextCounter1({super.key});
103103

104104
@override
105105
Widget build(BuildContext context) {
@@ -110,15 +110,15 @@ class TextCounter1 extends StatelessWidget {
110110
builder: (context, state) {
111111
return Text(
112112
'COUNTER 1: $state',
113-
style: Theme.of(context).textTheme.headline6,
113+
style: Theme.of(context).textTheme.titleLarge,
114114
);
115115
},
116116
);
117117
}
118118
}
119119

120120
class TextCounter2 extends StatelessWidget {
121-
const TextCounter2({Key? key}) : super(key: key);
121+
const TextCounter2({super.key});
122122

123123
@override
124124
Widget build(BuildContext context) {
@@ -129,15 +129,15 @@ class TextCounter2 extends StatelessWidget {
129129
builder: (context, state) {
130130
return Text(
131131
'COUNTER 2: $state',
132-
style: Theme.of(context).textTheme.headline6,
132+
style: Theme.of(context).textTheme.titleLarge,
133133
);
134134
},
135135
);
136136
}
137137
}
138138

139139
class IncrementButton extends StatelessWidget {
140-
const IncrementButton({Key? key}) : super(key: key);
140+
const IncrementButton({super.key});
141141

142142
@override
143143
Widget build(BuildContext context) {
@@ -152,7 +152,7 @@ class IncrementButton extends StatelessWidget {
152152
}
153153

154154
class TextBloc1 extends StatelessWidget {
155-
const TextBloc1({Key? key}) : super(key: key);
155+
const TextBloc1({super.key});
156156

157157
@override
158158
Widget build(BuildContext context) {

0 commit comments

Comments
 (0)