chore: Remove deprecations for v1.4.0 (#1978)

Just removes all the methods and classes that should be removed for v1.4.0
This commit is contained in:
Lukas Klingsbo
2022-10-01 15:16:46 +02:00
committed by GitHub
parent 50d4482dc6
commit f3aaacb9bc
5 changed files with 2 additions and 290 deletions

View File

@ -52,5 +52,6 @@ jobs:
channel: 'stable'
cache: true
- uses: bluefireteam/melos-action@main
- uses: bluefireteam/spec-action@main
- run: melos run test # TODO(spydon): Remove once Spec is fixed.
#- uses: bluefireteam/spec-action@main
# END TESTING STAGE

View File

@ -19,9 +19,6 @@ class OverlayManager {
return UnmodifiableListView(_activeOverlays);
}
@Deprecated('Use .activeOverlays instead. Will be removed in 1.4.0')
Set<String> get value => _activeOverlays.toSet();
/// Returns if the given [overlayName] is active
bool isActive(String overlayName) => _activeOverlays.contains(overlayName);

View File

@ -1,5 +1,3 @@
export 'src/flame_bloc_game.dart';
export 'src/flame_bloc_listenable.dart';
export 'src/flame_bloc_listener.dart';
export 'src/flame_bloc_provider.dart';

View File

@ -1,143 +0,0 @@
// ignore_for_file: deprecated_member_use_from_same_package
import 'dart:async';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
/// Adds capabilities for a [Component] to listen and have access
/// to a [Bloc] state.
@Deprecated('Use FlameBlocProvider and FlameBlocListenable instead')
mixin BlocComponent<B extends BlocBase<S>, S> on Component {
StreamSubscription<S>? _subscription;
S? _state;
/// The current state of the [Bloc] that this [Component] is listening to.
/// Flame keeps a copy of the state on the [Component] so this can be directly
/// accessed in both the [update] and the [render] method.
S? get state => _state;
/// Makes this component subscribe to the Bloc changes.
/// Visible only for test purposes.
@visibleForTesting
void subscribe(FlameBloc game) {
final _bloc = game.read<B>();
_state = _bloc.state;
_subscription = _bloc.stream.listen((newState) {
if (_state != newState) {
final _callNewState = listenWhen(_state, newState);
_state = newState;
if (_callNewState) {
onNewState(newState);
}
}
});
}
/// Makes this component stop listening to the [Bloc] changes.
/// Visible only for test purposes.
@visibleForTesting
void unsubscribe() {
_subscription?.cancel();
_subscription = null;
}
/// Override this to make [onNewState] be called only when
/// a certain state change happens.
///
/// Default implementation returns true.
bool listenWhen(S? previousState, S newState) => true;
/// Listener called everytime a new state is emitted to this component.
///
/// Default implementation is a no-op.
void onNewState(S state) {}
@override
@mustCallSuper
void onMount() {
super.onMount();
assert(
findGame()! is FlameBloc,
'BlocComponent can only be added to a FlameBloc game',
);
final game = findGame()! as FlameBloc;
if (game.isAttached) {
subscribe(game);
} else {
game.subscriptionQueue.add(this);
}
}
@override
@mustCallSuper
void onRemove() {
super.onRemove();
unsubscribe();
}
}
/// A mixin that enhances a [FlameGame] enabling features to receive
/// and emit changes to a [Bloc] state.
@Deprecated('Use FlameBlocProvider and FlameBlocListener instead')
mixin FlameBloc on FlameGame {
/// Contains a list of all of the [BlocComponent]s with an active
/// subscription. Only visible for testing.
@visibleForTesting
final List<BlocComponent> subscriptionQueue = [];
@override
@mustCallSuper
void onAttach() {
_runSubscriptionQueue();
}
@override
@mustCallSuper
void onRemove() {
super.onRemove();
_unsubscribe();
}
/// Convenience method for obtaining the nearest ancestor provider of type
/// [T].
///
/// This method will do a lookup in the tree for [T], so avoid calling this
/// inside the game loop methods like [update] and [render] to avoid
/// performance issues.
T read<T>() {
final context = buildContext;
if (context == null) {
throw Exception('build context is not available yet');
}
return context.read<T>();
}
void _runSubscriptionQueue() {
while (subscriptionQueue.isNotEmpty) {
final component = subscriptionQueue.removeAt(0);
component.subscribe(this);
}
}
void _unsubscribe() {
children.whereType<BlocComponent>().forEach((element) {
element.unsubscribe();
});
}
}
/// Provides a default, concrete implementation of a [FlameBloc] game.
@Deprecated('Use FlameBlocProvider and FlameBlocListener instead')
class FlameBlocGame extends FlameGame with FlameBloc {
/// FlameBlocGame constructor with an optional [Camera] as a parameter to
/// FlameGame.
@Deprecated('Use FlameBlocProvider and FlameBlocListener instead')
FlameBlocGame({super.camera});
}

View File

@ -1,141 +0,0 @@
// ignore_for_file: deprecated_member_use_from_same_package
import 'package:flame/components.dart';
import 'package:flame_bloc/flame_bloc.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
enum InventoryState {
sword,
bow,
}
class InventoryCubit extends Cubit<InventoryState> {
InventoryCubit() : super(InventoryState.sword);
void selectBow() {
emit(InventoryState.bow);
}
void selectSword() {
emit(InventoryState.bow);
}
}
class MyBlocGame extends FlameBlocGame {}
class InventoryComponent extends Component
with BlocComponent<InventoryCubit, InventoryState> {}
class MockInventoryComponent extends Component
with BlocComponent<InventoryCubit, InventoryState> {
int numSubscribeCalls = 0;
@override
void subscribe(FlameBloc game) {
numSubscribeCalls++;
}
}
void main() {
group('FlameBlocGame', () {
late InventoryCubit cubit;
setUp(() {
cubit = InventoryCubit();
});
final blocGame = FlameTester<MyBlocGame>(
MyBlocGame.new,
pumpWidget: (gameWidget, tester) async {
await tester.pumpWidget(
BlocProvider<InventoryCubit>.value(
value: cubit,
child: gameWidget,
),
);
},
);
blocGame.testGameWidget(
'can emit states',
verify: (game, tester) async {
game.read<InventoryCubit>().selectBow();
expect(cubit.state, equals(InventoryState.bow));
},
);
blocGame.test(
'read throws exception when game is not attached yet',
(game) {
expect(() => game.read<InventoryCubit>(), throwsException);
},
);
blocGame.test(
'adds component to queue when is not attached',
(game) {
game.add(InventoryComponent());
game.update(0);
expect(game.subscriptionQueue.length, equals(1));
},
);
blocGame.test(
'runs the queue when game is attached',
(game) {
final component = MockInventoryComponent();
game.add(component);
game.update(0);
expect(game.subscriptionQueue.length, 1);
game.onAttach();
expect(component.numSubscribeCalls, 1);
},
);
blocGame.testGameWidget(
'init components with the initial state',
setUp: (game, _) async {
await game.ensureAdd(InventoryComponent());
},
verify: (game, tester) async {
final component = game.firstChild<InventoryComponent>();
expect(component?.state, equals(InventoryState.sword));
},
);
blocGame.testGameWidget(
'Components can be removed',
setUp: (game, tester) async {
await game.ensureAdd(InventoryComponent());
},
verify: (game, tester) async {
expect(game.children.length, 1);
final component = game.firstChild<InventoryComponent>();
expect(component, isNotNull);
game.remove(component!);
game.update(0);
expect(game.children.length, 0);
},
);
blocGame.testGameWidget(
'components listen to changes',
setUp: (game, _) async {
await game.ensureAdd(InventoryComponent());
},
verify: (game, tester) async {
final component = game.firstChild<InventoryComponent>();
game.read<InventoryCubit>().selectBow();
expect(component?.state, equals(InventoryState.sword));
},
);
});
}