-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from VGVentures/refactor/app-flavors
refactor: app flavors
- Loading branch information
Showing
16 changed files
with
253 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:bloc/bloc.dart'; | ||
|
||
enum AppFlavor { one, two, three } | ||
|
||
class FlavorCubit extends Cubit<AppFlavor> { | ||
FlavorCubit() : super(AppFlavor.one); | ||
|
||
void select(AppFlavor flavor) => emit(flavor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'cubit/flavor_cubit.dart'; | ||
export 'view/flavor_button.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:financial_dashboard/flavor_button/flavor_button.dart'; | ||
import 'package:financial_dashboard/ui/ui.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class FlavorButton extends StatelessWidget { | ||
const FlavorButton({required this.flavor, super.key}); | ||
|
||
final AppFlavor flavor; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final currentFlavor = context.watch<FlavorCubit>().state; | ||
|
||
final outlinedIcon = switch (flavor) { | ||
AppFlavor.one => Icons.looks_one_outlined, | ||
AppFlavor.two => Icons.looks_two_outlined, | ||
AppFlavor.three => Icons.looks_3_outlined, | ||
}; | ||
|
||
final solidIcon = switch (flavor) { | ||
AppFlavor.one => Icons.looks_one, | ||
AppFlavor.two => Icons.looks_two, | ||
AppFlavor.three => Icons.looks_3, | ||
}; | ||
|
||
final icon = currentFlavor == flavor ? solidIcon : outlinedIcon; | ||
|
||
return Align( | ||
child: InkWell( | ||
onTap: () => context.read<FlavorCubit>().select(flavor), | ||
customBorder: const CircleBorder(), | ||
child: Padding( | ||
padding: const EdgeInsets.all(AppSpacing.sm), | ||
child: Icon(icon), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,59 @@ | ||
import 'package:financial_dashboard/demo/demo.dart'; | ||
import 'package:financial_dashboard/flavor_button/flavor_button.dart'; | ||
import 'package:financial_dashboard/theme_button/theme_button.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
import '../helpers/helpers.dart'; | ||
|
||
void main() { | ||
group('DemoPage', () { | ||
testWidgets('renders three DeviceFrames', (tester) async { | ||
testWidgets('renders DemoView', (tester) async { | ||
await tester.pumpExperience(const DemoPage()); | ||
expect(find.byType(DeviceFrame), findsNWidgets(3)); | ||
expect(find.byType(DemoView), findsOneWidget); | ||
}); | ||
}); | ||
|
||
group('DemoView', () { | ||
late FlavorCubit flavorCubit; | ||
late ThemeModeCubit themeModeCubit; | ||
|
||
setUp(() { | ||
flavorCubit = MockFlavorCubit(); | ||
themeModeCubit = MockThemeModeCubit(); | ||
|
||
when(() => themeModeCubit.state).thenReturn(ThemeMode.light); | ||
}); | ||
|
||
testWidgets('renders AppOne when AppFlavor is one', (tester) async { | ||
when(() => flavorCubit.state).thenReturn(AppFlavor.one); | ||
await tester.pumpExperience( | ||
const DemoView(), | ||
flavorCubit: flavorCubit, | ||
themeModeCubit: themeModeCubit, | ||
); | ||
expect(find.byType(AppOne), findsOneWidget); | ||
}); | ||
|
||
testWidgets('renders AppTwo when AppFlavor is two', (tester) async { | ||
when(() => flavorCubit.state).thenReturn(AppFlavor.two); | ||
await tester.pumpExperience( | ||
const DemoView(), | ||
flavorCubit: flavorCubit, | ||
themeModeCubit: themeModeCubit, | ||
); | ||
expect(find.byType(AppTwo), findsOneWidget); | ||
}); | ||
|
||
testWidgets('renders AppThree when AppFlavor is three', (tester) async { | ||
when(() => flavorCubit.state).thenReturn(AppFlavor.three); | ||
await tester.pumpExperience( | ||
const DemoView(), | ||
flavorCubit: flavorCubit, | ||
themeModeCubit: themeModeCubit, | ||
); | ||
expect(find.byType(AppThree), findsOneWidget); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:financial_dashboard/flavor_button/cubit/flavor_cubit.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('FlavorCubit', () { | ||
blocTest<FlavorCubit, AppFlavor>( | ||
'initial state is AppFlavor.one', | ||
build: FlavorCubit.new, | ||
verify: (cubit) => expect(cubit.state, AppFlavor.one), | ||
); | ||
|
||
blocTest<FlavorCubit, AppFlavor>( | ||
'select method changes AppFlavor', | ||
build: FlavorCubit.new, | ||
act: (cubit) => cubit.select(AppFlavor.two), | ||
expect: () => [AppFlavor.two], | ||
); | ||
}); | ||
} |
Oops, something went wrong.