mirror of https://github.com/flutter/pinball.git
chore: remove generated counter example (#1)
parent
a12f1d388d
commit
5ab34687a0
@ -1,9 +0,0 @@
|
|||||||
// Copyright (c) 2021, Very Good Ventures
|
|
||||||
// https://verygood.ventures
|
|
||||||
//
|
|
||||||
// Use of this source code is governed by an MIT-style
|
|
||||||
// license that can be found in the LICENSE file or at
|
|
||||||
// https://opensource.org/licenses/MIT.
|
|
||||||
|
|
||||||
export 'cubit/counter_cubit.dart';
|
|
||||||
export 'view/counter_page.dart';
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (c) 2021, Very Good Ventures
|
|
||||||
// https://verygood.ventures
|
|
||||||
//
|
|
||||||
// Use of this source code is governed by an MIT-style
|
|
||||||
// license that can be found in the LICENSE file or at
|
|
||||||
// https://opensource.org/licenses/MIT.
|
|
||||||
|
|
||||||
import 'package:bloc/bloc.dart';
|
|
||||||
|
|
||||||
class CounterCubit extends Cubit<int> {
|
|
||||||
CounterCubit() : super(0);
|
|
||||||
|
|
||||||
void increment() => emit(state + 1);
|
|
||||||
void decrement() => emit(state - 1);
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
// Copyright (c) 2021, Very Good Ventures
|
|
||||||
// https://verygood.ventures
|
|
||||||
//
|
|
||||||
// Use of this source code is governed by an MIT-style
|
|
||||||
// license that can be found in the LICENSE file or at
|
|
||||||
// https://opensource.org/licenses/MIT.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:pinball/counter/counter.dart';
|
|
||||||
import 'package:pinball/l10n/l10n.dart';
|
|
||||||
|
|
||||||
class CounterPage extends StatelessWidget {
|
|
||||||
const CounterPage({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return BlocProvider(
|
|
||||||
create: (_) => CounterCubit(),
|
|
||||||
child: const CounterView(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CounterView extends StatelessWidget {
|
|
||||||
const CounterView({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final l10n = context.l10n;
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title: Text(l10n.counterAppBarTitle)),
|
|
||||||
body: const Center(child: CounterText()),
|
|
||||||
floatingActionButton: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
FloatingActionButton(
|
|
||||||
onPressed: () => context.read<CounterCubit>().increment(),
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
FloatingActionButton(
|
|
||||||
onPressed: () => context.read<CounterCubit>().decrement(),
|
|
||||||
child: const Icon(Icons.remove),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CounterText extends StatelessWidget {
|
|
||||||
const CounterText({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
final count = context.select((CounterCubit cubit) => cubit.state);
|
|
||||||
return Text('$count', style: theme.textTheme.headline1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright (c) 2021, Very Good Ventures
|
|
||||||
// https://verygood.ventures
|
|
||||||
//
|
|
||||||
// Use of this source code is governed by an MIT-style
|
|
||||||
// license that can be found in the LICENSE file or at
|
|
||||||
// https://opensource.org/licenses/MIT.
|
|
||||||
|
|
||||||
import 'package:bloc_test/bloc_test.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
|
|
||||||
import 'package:pinball/counter/counter.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group('CounterCubit', () {
|
|
||||||
test('initial state is 0', () {
|
|
||||||
expect(CounterCubit().state, equals(0));
|
|
||||||
});
|
|
||||||
|
|
||||||
blocTest<CounterCubit, int>(
|
|
||||||
'emits [1] when increment is called',
|
|
||||||
build: CounterCubit.new,
|
|
||||||
act: (cubit) => cubit.increment(),
|
|
||||||
expect: () => [equals(1)],
|
|
||||||
);
|
|
||||||
|
|
||||||
blocTest<CounterCubit, int>(
|
|
||||||
'emits [-1] when decrement is called',
|
|
||||||
build: CounterCubit.new,
|
|
||||||
act: (cubit) => cubit.decrement(),
|
|
||||||
expect: () => [equals(-1)],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
// Copyright (c) 2021, Very Good Ventures
|
|
||||||
// https://verygood.ventures
|
|
||||||
//
|
|
||||||
// Use of this source code is governed by an MIT-style
|
|
||||||
// license that can be found in the LICENSE file or at
|
|
||||||
// https://opensource.org/licenses/MIT.
|
|
||||||
|
|
||||||
import 'package:bloc_test/bloc_test.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:mocktail/mocktail.dart';
|
|
||||||
|
|
||||||
import 'package:pinball/counter/counter.dart';
|
|
||||||
|
|
||||||
import '../../helpers/helpers.dart';
|
|
||||||
|
|
||||||
class MockCounterCubit extends MockCubit<int> implements CounterCubit {}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group('CounterPage', () {
|
|
||||||
testWidgets('renders CounterView', (tester) async {
|
|
||||||
await tester.pumpApp(const CounterPage());
|
|
||||||
expect(find.byType(CounterView), findsOneWidget);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('CounterView', () {
|
|
||||||
late CounterCubit counterCubit;
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
counterCubit = MockCounterCubit();
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('renders current count', (tester) async {
|
|
||||||
const state = 42;
|
|
||||||
when(() => counterCubit.state).thenReturn(state);
|
|
||||||
await tester.pumpApp(
|
|
||||||
BlocProvider.value(
|
|
||||||
value: counterCubit,
|
|
||||||
child: const CounterView(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(find.text('$state'), findsOneWidget);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('calls increment when increment button is tapped',
|
|
||||||
(tester) async {
|
|
||||||
when(() => counterCubit.state).thenReturn(0);
|
|
||||||
when(() => counterCubit.increment()).thenReturn(null);
|
|
||||||
await tester.pumpApp(
|
|
||||||
BlocProvider.value(
|
|
||||||
value: counterCubit,
|
|
||||||
child: const CounterView(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await tester.tap(find.byIcon(Icons.add));
|
|
||||||
verify(() => counterCubit.increment()).called(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('calls decrement when decrement button is tapped',
|
|
||||||
(tester) async {
|
|
||||||
when(() => counterCubit.state).thenReturn(0);
|
|
||||||
when(() => counterCubit.decrement()).thenReturn(null);
|
|
||||||
await tester.pumpApp(
|
|
||||||
BlocProvider.value(
|
|
||||||
value: counterCubit,
|
|
||||||
child: const CounterView(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await tester.tap(find.byIcon(Icons.remove));
|
|
||||||
verify(() => counterCubit.decrement()).called(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in new issue