-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AdvancedEditor): add filled button theme editor (#1270)
- Loading branch information
Showing
15 changed files
with
170 additions
and
7 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
23 changes: 23 additions & 0 deletions
23
lib/button_theme/filled_button_theme/filled_button_theme_cubit.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,23 @@ | ||
import 'package:appainter/button_theme/button_theme.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class FilledButtonThemeCubit extends AbstractFlatButtonStyleCubit { | ||
FilledButtonThemeCubit({required super.colorThemeCubit}); | ||
|
||
@override | ||
OutlinedBorder get defaultShape => const StadiumBorder(); | ||
|
||
@override | ||
ButtonStyle getDefaultStyle(ColorScheme colorScheme) { | ||
return FilledButton.styleFrom( | ||
backgroundColor: colorScheme.secondaryContainer, | ||
foregroundColor: colorScheme.onSecondaryContainer, | ||
disabledBackgroundColor: colorScheme.onSurface.withOpacity(0.12), | ||
disabledForegroundColor: colorScheme.onSurface.withOpacity(0.38), | ||
shadowColor: colorScheme.shadow, | ||
elevation: 0, | ||
minimumSize: const Size(64, 40), | ||
shape: defaultShape, | ||
); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
lib/button_theme/filled_button_theme/filled_button_theme_editor.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,9 @@ | ||
import 'package:appainter/button_theme/button_theme.dart'; | ||
|
||
class FilledButtonThemeEditor | ||
extends AbstractFlatButtonStyleEditor<FilledButtonThemeCubit> { | ||
const FilledButtonThemeEditor({super.key}); | ||
|
||
@override | ||
String get header => 'Filled button'; | ||
} |
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
48 changes: 48 additions & 0 deletions
48
test/button_theme/filled_button_theme/filled_button_theme_cubit_test.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,48 @@ | ||
import 'package:appainter/button_theme/button_theme.dart'; | ||
import 'package:appainter/color_theme/color_theme.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
import '../../mocks.dart'; | ||
import '../../utils.dart'; | ||
|
||
void main() { | ||
final colorScheme = ThemeData().colorScheme; | ||
const shape = StadiumBorder(); | ||
|
||
late ColorThemeCubit colorThemeCubit; | ||
late FilledButtonThemeCubit sut; | ||
|
||
setUp(() { | ||
colorThemeCubit = MockColorThemeCubit(); | ||
when(() => colorThemeCubit.state).thenReturn(ColorThemeState()); | ||
|
||
sut = FilledButtonThemeCubit(colorThemeCubit: colorThemeCubit); | ||
}); | ||
|
||
test('default shape', () { | ||
final actual = sut.defaultShape; | ||
expect(actual, equals(shape)); | ||
}); | ||
|
||
test('get default style', () { | ||
final actual = sut.getDefaultStyle(colorScheme); | ||
final expected = FilledButton.styleFrom( | ||
backgroundColor: colorScheme.secondaryContainer, | ||
foregroundColor: colorScheme.onSecondaryContainer, | ||
disabledBackgroundColor: colorScheme.onSurface.withOpacity(0.12), | ||
disabledForegroundColor: colorScheme.onSurface.withOpacity(0.38), | ||
shadowColor: colorScheme.shadow, | ||
elevation: 0, | ||
minimumSize: const Size(64, 40), | ||
shape: shape, | ||
); | ||
|
||
verifyMaterialProperty(actual.backgroundColor!, expected.backgroundColor!); | ||
verifyMaterialProperty(actual.foregroundColor!, expected.foregroundColor!); | ||
verifyMaterialProperty(actual.overlayColor!, expected.overlayColor!); | ||
verifyMaterialProperty(actual.shadowColor!, expected.shadowColor!); | ||
verifyMaterialProperty(actual.elevation!, expected.elevation!); | ||
}); | ||
} |
20 changes: 20 additions & 0 deletions
20
test/button_theme/filled_button_theme/filled_button_theme_editor_test.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,20 @@ | ||
import 'package:appainter/button_theme/button_theme.dart'; | ||
import 'package:appainter/color_theme/color_theme.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
import '../../mocks.dart'; | ||
|
||
Future<void> main() async { | ||
late ColorThemeCubit colorThemeCubit; | ||
late FilledButtonThemeEditor sut; | ||
|
||
setUp(() { | ||
colorThemeCubit = MockColorThemeCubit(); | ||
when(() => colorThemeCubit.state).thenReturn(ColorThemeState()); | ||
|
||
sut = const FilledButtonThemeEditor(); | ||
}); | ||
|
||
test('header', () => expect(sut.header, equals('Filled button'))); | ||
} |
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