mirror of https://github.com/flutter/pinball.git
parent
0eac420e83
commit
5c095e8f93
@ -0,0 +1,13 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:pinball/character_themes/character_themes.dart';
|
||||||
|
|
||||||
|
part 'theme_state.dart';
|
||||||
|
|
||||||
|
class ThemeCubit extends Cubit<ThemeState> {
|
||||||
|
ThemeCubit() : super(const ThemeState(DashTheme()));
|
||||||
|
|
||||||
|
void themeSelected(CharacterTheme theme) {
|
||||||
|
emit(ThemeState(theme));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
part of 'theme_cubit.dart';
|
||||||
|
|
||||||
|
class ThemeState extends Equatable {
|
||||||
|
const ThemeState(this.theme);
|
||||||
|
|
||||||
|
final CharacterTheme theme;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [theme];
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball/character_themes/character_themes.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('ThemeCubit', () {
|
||||||
|
test('initial state has Dash theme', () {
|
||||||
|
final themeCubit = ThemeCubit();
|
||||||
|
expect(themeCubit.state.theme, equals(const DashTheme()));
|
||||||
|
});
|
||||||
|
|
||||||
|
group('themeSelected', () {
|
||||||
|
blocTest<ThemeCubit, ThemeState>(
|
||||||
|
'emits selected theme',
|
||||||
|
build: ThemeCubit.new,
|
||||||
|
act: (bloc) => bloc.themeSelected(const SparkyTheme()),
|
||||||
|
expect: () => [
|
||||||
|
const ThemeState(SparkyTheme()),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
// ignore_for_file: prefer_const_constructors
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball/character_themes/character_themes.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('ThemeState', () {
|
||||||
|
test('can be instantiated', () {
|
||||||
|
expect(const ThemeState(DashTheme()), isNotNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('supports value equality', () {
|
||||||
|
expect(
|
||||||
|
ThemeState(DashTheme()),
|
||||||
|
equals(const ThemeState(DashTheme())),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue