Skip to content

Commit

Permalink
feat: add font family support to app bar theme (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeshuaro authored Dec 15, 2022
1 parent 5c52ba4 commit 00ff9d8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
12 changes: 9 additions & 3 deletions lib/abstract_text_style/cubit/abstract_text_style_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:appainter/common/common.dart';
import 'package:appainter/models/models.dart';
import 'package:appainter/services/services.dart';
import 'package:appainter/text_theme/text_theme.dart';
import 'package:bloc/bloc.dart';
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:appainter/common/common.dart';
import 'package:appainter/models/models.dart';
import 'package:appainter/services/services.dart';

part 'abstract_text_style_cubit.g.dart';
part 'text_style_state.dart';
Expand Down Expand Up @@ -148,4 +149,9 @@ abstract class AbstractTextStyleCubit extends Cubit<TextStyleState> {
emit(state.copyWith(style: style));
}
}

void fontFamilyChanged(FontData data) {
final style = state.style.merge(data.style);
emit(state.copyWith(style: style));
}
}
4 changes: 3 additions & 1 deletion lib/abstract_text_style/view/abstract_text_style_editor.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:appainter/abstract_text_style/abstract_text_style.dart';
import 'package:appainter/common/common.dart';
import 'package:appainter/font/font.dart';
import 'package:appainter/models/models.dart';
import 'package:appainter/services/services.dart';
import 'package:appainter/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:appainter/widgets/widgets.dart';

abstract class AbstractTextStyleEditor<T extends AbstractTextStyleCubit>
extends ExpansionPanelItem {
Expand All @@ -20,6 +21,7 @@ abstract class AbstractTextStyleEditor<T extends AbstractTextStyleCubit>
return SideBySideList(
padding: kPaddingAll,
children: [
FontPicker(onChanged: cubit.fontFamilyChanged),
ColorListTile(
key: const Key('colorPicker'),
title: 'Color',
Expand Down
48 changes: 31 additions & 17 deletions test/abstract_text_style/abstract_text_style_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import 'package:appainter/abstract_text_style/abstract_text_style.dart';
import 'package:appainter/common/common.dart';
import 'package:appainter/models/models.dart';
import 'package:appainter/services/services.dart';
import 'package:appainter/text_theme/text_theme.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_fonts/google_fonts.dart';

import '../utils.dart';
import 'mocks.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final fontData = FontData('aBeeZee', GoogleFonts.aBeeZee());

late TestTextStyleCubit cubit;
late TextStyle style;
late Color color;
Expand All @@ -30,7 +35,7 @@ void main() {
group('test style brightness', () {
for (var isDark in [true, false]) {
blocTest<TestTextStyleCubit, TextStyleState>(
'should emit style with isDark=$isDark',
'emit style with isDark=$isDark',
build: () => cubit,
act: (cubit) => cubit.styleBrightnessChanged(isDark),
expect: () => [
Expand All @@ -45,21 +50,21 @@ void main() {
});

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit style',
'emit style',
build: () => cubit,
act: (cubit) => cubit.styleChanged(style),
expect: () => [TextStyleState(style: style)],
);

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit color',
'emit color',
build: () => cubit,
act: (cubit) => cubit.colorChanged(color),
expect: () => [TextStyleState(style: style.copyWith(color: color))],
);

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit background color',
'emit background color',
build: () => cubit,
act: (cubit) => cubit.backgroundColorChanged(color),
expect: () => [
Expand All @@ -68,7 +73,7 @@ void main() {
);

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit font size',
'emit font size',
build: () => cubit,
act: (cubit) => cubit.fontSizeChanged(doubleStr),
expect: () => [
Expand All @@ -79,7 +84,7 @@ void main() {
group('test font weights', () {
for (var weight in MyFontWeight().values) {
blocTest<TestTextStyleCubit, TextStyleState>(
'should emit $weight',
'emit $weight',
build: () => cubit,
act: (cubit) {
cubit.fontWeightChanged(MyFontWeight().convertToString(weight)!);
Expand All @@ -94,7 +99,7 @@ void main() {
group('test font styles', () {
for (var fontStyle in FontStyle.values) {
blocTest<TestTextStyleCubit, TextStyleState>(
'should emit $fontStyle',
'emit $fontStyle',
build: () => cubit,
act: (cubit) {
cubit.fontStyleChanged(UtilService.enumToString(fontStyle));
Expand All @@ -107,7 +112,7 @@ void main() {
});

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit letter spacing',
'emit letter spacing',
build: () => cubit,
act: (cubit) => cubit.letterSpacingChanged(doubleStr),
expect: () => [
Expand All @@ -116,7 +121,7 @@ void main() {
);

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit word spacing',
'emit word spacing',
build: () => cubit,
act: (cubit) => cubit.wordSpacingChanged(doubleStr),
expect: () => [
Expand All @@ -127,7 +132,7 @@ void main() {
group('test text baselines', () {
for (var baseline in TextBaseline.values) {
blocTest<TestTextStyleCubit, TextStyleState>(
'should emit $baseline',
'emit $baseline',
build: () => cubit,
act: (cubit) {
cubit.textBaselineChanged(UtilService.enumToString(baseline));
Expand All @@ -140,7 +145,7 @@ void main() {
});

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit height',
'emit height',
build: () => cubit,
act: (cubit) => cubit.heightChanged(doubleStr),
expect: () => [
Expand All @@ -151,7 +156,7 @@ void main() {
group('test leading distributions', () {
for (var dist in TextLeadingDistribution.values) {
blocTest<TestTextStyleCubit, TextStyleState>(
'should emit $dist',
'emit $dist',
build: () => cubit,
act: (cubit) {
cubit.leadingDistributionChanged(UtilService.enumToString(dist));
Expand All @@ -166,7 +171,7 @@ void main() {
group('test decorations', () {
for (var decoration in MyTextDecoration().values) {
blocTest<TestTextStyleCubit, TextStyleState>(
'should emit $decoration',
'emit $decoration',
build: () => cubit,
act: (cubit) {
cubit.decorationChanged(
Expand All @@ -181,7 +186,7 @@ void main() {
});

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit decoration color',
'emit decoration color',
build: () => cubit,
act: (cubit) => cubit.decorationColorChanged(color),
expect: () => [
Expand All @@ -191,7 +196,7 @@ void main() {

group('text decoration styles', () {
blocTest<TestTextStyleCubit, TextStyleState>(
'should emit null',
'emit null',
build: () => cubit,
act: (cubit) => cubit.decorationStyleChanged(kNone),
expect: () => [
Expand All @@ -201,7 +206,7 @@ void main() {

for (var decorationStyle in TextDecorationStyle.values) {
blocTest<TestTextStyleCubit, TextStyleState>(
'should emit $decorationStyle',
'emit $decorationStyle',
build: () => cubit,
act: (cubit) {
cubit.decorationStyleChanged(
Expand All @@ -218,11 +223,20 @@ void main() {
});

blocTest<TestTextStyleCubit, TextStyleState>(
'should emit decoration thickness',
'emit decoration thickness',
build: () => cubit,
act: (cubit) => cubit.decorationThicknessChanged(doubleStr),
expect: () => [
TextStyleState(style: style.copyWith(decorationThickness: doubleNum)),
],
);

blocTest<TestTextStyleCubit, TextStyleState>(
'emit font family',
build: () => cubit,
act: (cubit) => cubit.fontFamilyChanged(fontData),
expect: () => [
TextStyleState(style: style.merge(fontData.style)),
],
);
}

0 comments on commit 00ff9d8

Please sign in to comment.