Add font scaling

This commit is contained in:
Hillel Coren 2021-12-05 09:15:11 +02:00
parent e883d03737
commit 8f3a25a9c1
3 changed files with 353 additions and 297 deletions

View File

@ -250,6 +250,12 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
state.prefState.enableDarkMode ? Colors.white : Colors.black87,
);
// https://stackoverflow.com/a/69883043/497368
MediaQueryData windowData =
MediaQueryData.fromWindow(WidgetsBinding.instance.window);
windowData = windowData.copyWith(
textScaleFactor: state.prefState.textScaleFactor);
return StyledToast(
locale: locale,
duration: Duration(seconds: 3),
@ -262,12 +268,15 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
),
child: WebSocketRefresh(
companyId: state.company?.id,
child: MediaQuery(
data: windowData,
child: MaterialApp(
useInheritedMediaQuery: true,
scrollBehavior: MyCustomScrollBehavior(),
navigatorKey: navigatorKey,
supportedLocales: kLanguages
.map(
(String locale) => AppLocalization.createLocale(locale))
.map((String locale) =>
AppLocalization.createLocale(locale))
.toList(),
debugShowCheckedModeBanner: false,
//showPerformanceOverlay: true,
@ -303,8 +312,8 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
primaryColorDark: Colors.black,
textButtonTheme:
TextButtonThemeData(style: textButtonTheme),
outlinedButtonTheme:
OutlinedButtonThemeData(style: outlinedButtonTheme),
outlinedButtonTheme: OutlinedButtonThemeData(
style: outlinedButtonTheme),
)
: ThemeData(
colorScheme: ColorScheme.fromSwatch()
@ -340,17 +349,19 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
appBarTheme: AppBarTheme(
color: hasAccentColor ? accentColor : Colors.white,
iconTheme: IconThemeData(
color: hasAccentColor ? Colors.white : accentColor,
color:
hasAccentColor ? Colors.white : accentColor,
),
titleTextStyle: TextStyle(
fontSize: 20,
color:
hasAccentColor ? Colors.white : Colors.black),
color: hasAccentColor
? Colors.white
: Colors.black),
),
textButtonTheme:
TextButtonThemeData(style: textButtonTheme),
outlinedButtonTheme:
OutlinedButtonThemeData(style: outlinedButtonTheme),
outlinedButtonTheme: OutlinedButtonThemeData(
style: outlinedButtonTheme),
),
title: kAppName,
onGenerateRoute: isMobile(context) ? null : generateRoute,
@ -370,9 +381,12 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
ProductViewScreen(),
ProductEditScreen.route: (context) =>
ProductEditScreen(),
ClientScreen.route: (context) => ClientScreenBuilder(),
ClientViewScreen.route: (context) => ClientViewScreen(),
ClientEditScreen.route: (context) => ClientEditScreen(),
ClientScreen.route: (context) =>
ClientScreenBuilder(),
ClientViewScreen.route: (context) =>
ClientViewScreen(),
ClientEditScreen.route: (context) =>
ClientEditScreen(),
ClientPdfScreen.route: (context) => ClientPdfScreen(),
InvoiceScreen.route: (context) =>
InvoiceScreenBuilder(),
@ -382,7 +396,8 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
InvoiceEditScreen(),
InvoiceEmailScreen.route: (context) =>
InvoiceEmailScreen(),
InvoicePdfScreen.route: (context) => InvoicePdfScreen(),
InvoicePdfScreen.route: (context) =>
InvoicePdfScreen(),
DocumentScreen.route: (context) =>
DocumentScreenBuilder(),
DocumentViewScreen.route: (context) =>
@ -395,9 +410,12 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
ExpenseViewScreen(),
ExpenseEditScreen.route: (context) =>
ExpenseEditScreen(),
VendorScreen.route: (context) => VendorScreenBuilder(),
VendorViewScreen.route: (context) => VendorViewScreen(),
VendorEditScreen.route: (context) => VendorEditScreen(),
VendorScreen.route: (context) =>
VendorScreenBuilder(),
VendorViewScreen.route: (context) =>
VendorViewScreen(),
VendorEditScreen.route: (context) =>
VendorEditScreen(),
TaskScreen.route: (context) => TaskScreenBuilder(),
TaskViewScreen.route: (context) => TaskViewScreen(),
TaskEditScreen.route: (context) => TaskEditScreen(),
@ -418,7 +436,8 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
QuoteScreen.route: (context) => QuoteScreenBuilder(),
QuoteViewScreen.route: (context) => QuoteViewScreen(),
QuoteEditScreen.route: (context) => QuoteEditScreen(),
QuoteEmailScreen.route: (context) => QuoteEmailScreen(),
QuoteEmailScreen.route: (context) =>
QuoteEmailScreen(),
QuotePdfScreen.route: (context) => QuotePdfScreen(),
// STARTER: routes - do not remove comment
RecurringExpenseScreen.route: (context) =>
@ -470,12 +489,18 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
PaymentTermEditScreen(),
PaymentTermViewScreen.route: (context) =>
PaymentTermViewScreen(),
DesignScreen.route: (context) => DesignScreenBuilder(),
DesignViewScreen.route: (context) => DesignViewScreen(),
DesignEditScreen.route: (context) => DesignEditScreen(),
CreditScreen.route: (context) => CreditScreenBuilder(),
CreditViewScreen.route: (context) => CreditViewScreen(),
CreditEditScreen.route: (context) => CreditEditScreen(),
DesignScreen.route: (context) =>
DesignScreenBuilder(),
DesignViewScreen.route: (context) =>
DesignViewScreen(),
DesignEditScreen.route: (context) =>
DesignEditScreen(),
CreditScreen.route: (context) =>
CreditScreenBuilder(),
CreditViewScreen.route: (context) =>
CreditViewScreen(),
CreditEditScreen.route: (context) =>
CreditEditScreen(),
CreditEmailScreen.route: (context) =>
CreditEmailScreen(),
CreditPdfScreen.route: (context) => CreditPdfScreen(),
@ -548,6 +573,7 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
: {},
),
),
),
);
}),
),

View File

@ -29,6 +29,7 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
requireAuthentication: false,
colorTheme: kColorThemeLight,
isFilterVisible: false,
textScaleFactor: 1,
longPressSelectionIsDefault: true,
tapSelectedToEdit: false,
hideDesktopWarning: false,
@ -44,6 +45,11 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
PrefState._();
static const TEXT_SCALING_NORMAL = 1.0;
static const TEXT_SCALING_LARGE = 1.2;
static const TEXT_SCALING_LARGER = 1.4;
static const TEXT_SCALING_LARGEST = 1.6;
static const THEME_SIDEBAR_ACTIVE_BACKGROUND_COLOR =
'sidebar_active_background_color';
static const THEME_SIDEBAR_ACTIVE_FONT_COLOR = 'sidebar_active_font_color';
@ -123,6 +129,8 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
bool get hideDesktopWarning;
double get textScaleFactor;
BuiltMap<EntityType, PrefStateSortField> get sortFields;
ColorTheme get colorThemeModel => colorThemesMap.containsKey(colorTheme)
@ -190,6 +198,7 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
..persistData = false
..persistUI = true
..showPdfPreview = true
..textScaleFactor = 1
..colorTheme =
builder.enableDarkMode == true ? kColorThemeLight : kColorThemeLight;

View File

@ -178,6 +178,9 @@ class _$PrefStateSerializer implements StructuredSerializer<PrefState> {
'hideDesktopWarning',
serializers.serialize(object.hideDesktopWarning,
specifiedType: const FullType(bool)),
'textScaleFactor',
serializers.serialize(object.textScaleFactor,
specifiedType: const FullType(double)),
'sortFields',
serializers.serialize(object.sortFields,
specifiedType: const FullType(BuiltMap, const [
@ -292,6 +295,10 @@ class _$PrefStateSerializer implements StructuredSerializer<PrefState> {
result.hideDesktopWarning = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool;
break;
case 'textScaleFactor':
result.textScaleFactor = serializers.deserialize(value,
specifiedType: const FullType(double)) as double;
break;
case 'sortFields':
result.sortFields.replace(serializers.deserialize(value,
specifiedType: const FullType(BuiltMap, const [
@ -579,6 +586,8 @@ class _$PrefState extends PrefState {
@override
final bool hideDesktopWarning;
@override
final double textScaleFactor;
@override
final BuiltMap<EntityType, PrefStateSortField> sortFields;
@override
final BuiltMap<String, CompanyPrefState> companyPrefs;
@ -608,6 +617,7 @@ class _$PrefState extends PrefState {
this.rowsPerPage,
this.colorTheme,
this.hideDesktopWarning,
this.textScaleFactor,
this.sortFields,
this.companyPrefs})
: super._() {
@ -651,6 +661,8 @@ class _$PrefState extends PrefState {
colorTheme, 'PrefState', 'colorTheme');
BuiltValueNullFieldError.checkNotNull(
hideDesktopWarning, 'PrefState', 'hideDesktopWarning');
BuiltValueNullFieldError.checkNotNull(
textScaleFactor, 'PrefState', 'textScaleFactor');
BuiltValueNullFieldError.checkNotNull(
sortFields, 'PrefState', 'sortFields');
BuiltValueNullFieldError.checkNotNull(
@ -689,6 +701,7 @@ class _$PrefState extends PrefState {
rowsPerPage == other.rowsPerPage &&
colorTheme == other.colorTheme &&
hideDesktopWarning == other.hideDesktopWarning &&
textScaleFactor == other.textScaleFactor &&
sortFields == other.sortFields &&
companyPrefs == other.companyPrefs;
}
@ -714,8 +727,7 @@ class _$PrefState extends PrefState {
$jc(
$jc(
$jc(
$jc($jc($jc($jc($jc(0, appLayout.hashCode), moduleLayout.hashCode), menuSidebarMode.hashCode), historySidebarMode.hashCode),
useSidebarEditor.hashCode),
$jc($jc($jc($jc($jc($jc(0, appLayout.hashCode), moduleLayout.hashCode), menuSidebarMode.hashCode), historySidebarMode.hashCode), useSidebarEditor.hashCode),
customColors.hashCode),
isPreviewVisible.hashCode),
isMenuVisible.hashCode),
@ -732,6 +744,7 @@ class _$PrefState extends PrefState {
rowsPerPage.hashCode),
colorTheme.hashCode),
hideDesktopWarning.hashCode),
textScaleFactor.hashCode),
sortFields.hashCode),
companyPrefs.hashCode));
}
@ -760,6 +773,7 @@ class _$PrefState extends PrefState {
..add('rowsPerPage', rowsPerPage)
..add('colorTheme', colorTheme)
..add('hideDesktopWarning', hideDesktopWarning)
..add('textScaleFactor', textScaleFactor)
..add('sortFields', sortFields)
..add('companyPrefs', companyPrefs))
.toString();
@ -870,6 +884,11 @@ class PrefStateBuilder implements Builder<PrefState, PrefStateBuilder> {
set hideDesktopWarning(bool hideDesktopWarning) =>
_$this._hideDesktopWarning = hideDesktopWarning;
double _textScaleFactor;
double get textScaleFactor => _$this._textScaleFactor;
set textScaleFactor(double textScaleFactor) =>
_$this._textScaleFactor = textScaleFactor;
MapBuilder<EntityType, PrefStateSortField> _sortFields;
MapBuilder<EntityType, PrefStateSortField> get sortFields =>
_$this._sortFields ??= new MapBuilder<EntityType, PrefStateSortField>();
@ -910,6 +929,7 @@ class PrefStateBuilder implements Builder<PrefState, PrefStateBuilder> {
_rowsPerPage = $v.rowsPerPage;
_colorTheme = $v.colorTheme;
_hideDesktopWarning = $v.hideDesktopWarning;
_textScaleFactor = $v.textScaleFactor;
_sortFields = $v.sortFields.toBuilder();
_companyPrefs = $v.companyPrefs.toBuilder();
_$v = null;
@ -963,6 +983,7 @@ class PrefStateBuilder implements Builder<PrefState, PrefStateBuilder> {
rowsPerPage: BuiltValueNullFieldError.checkNotNull(rowsPerPage, 'PrefState', 'rowsPerPage'),
colorTheme: BuiltValueNullFieldError.checkNotNull(colorTheme, 'PrefState', 'colorTheme'),
hideDesktopWarning: BuiltValueNullFieldError.checkNotNull(hideDesktopWarning, 'PrefState', 'hideDesktopWarning'),
textScaleFactor: BuiltValueNullFieldError.checkNotNull(textScaleFactor, 'PrefState', 'textScaleFactor'),
sortFields: sortFields.build(),
companyPrefs: companyPrefs.build());
} catch (_) {