Settings
This commit is contained in:
parent
ebe90a515c
commit
614ffcdc25
|
|
@ -236,6 +236,7 @@ const String kExpenseStatusInvoiced = '3';
|
||||||
|
|
||||||
const String kDefaultCurrencyId = '1';
|
const String kDefaultCurrencyId = '1';
|
||||||
const String kDefaultDateFormat = '5';
|
const String kDefaultDateFormat = '5';
|
||||||
|
const String kDefaultAccentColor = '#FF40C4FF';
|
||||||
|
|
||||||
const String kActivityEmailInvoice = '6';
|
const String kActivityEmailInvoice = '6';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ void main({bool isTesting = false}) async {
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode) ?? true;
|
final enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode) ?? true;
|
||||||
final accentColor = prefs.getString(kSharedPrefAccentColor) ?? '#FF0000';
|
final accentColor = prefs.getString(kSharedPrefAccentColor) ?? kDefaultAccentColor;
|
||||||
|
|
||||||
final longPressSelectionIsDefault =
|
final longPressSelectionIsDefault =
|
||||||
prefs.getBool(kSharedPrefLongPressSelectionIsDefault) ?? false;
|
prefs.getBool(kSharedPrefLongPressSelectionIsDefault) ?? false;
|
||||||
|
|
@ -267,13 +267,11 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
|
||||||
? ThemeData(
|
? ThemeData(
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
accentColor:
|
accentColor:
|
||||||
convertHexStringToColor(state.uiState.accentColor) ??
|
convertHexStringToColor(state.uiState.accentColor),
|
||||||
Colors.lightBlueAccent,
|
|
||||||
)
|
)
|
||||||
: ThemeData().copyWith(
|
: ThemeData().copyWith(
|
||||||
accentColor: state.uiState.accentColor == null
|
accentColor:
|
||||||
? null
|
convertHexStringToColor(state.uiState.accentColor),
|
||||||
: convertHexStringToColor(state.uiState.accentColor),
|
|
||||||
primaryColor: const Color(0xFF117cc1),
|
primaryColor: const Color(0xFF117cc1),
|
||||||
primaryColorLight: const Color(0xFF5dabf4),
|
primaryColorLight: const Color(0xFF5dabf4),
|
||||||
primaryColorDark: const Color(0xFF0D5D91),
|
primaryColorDark: const Color(0xFF0D5D91),
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
//return 'Custom fields [UI]: ${uiState.settingsUIState.userCompany.company.customFields}, [DB] ${selectedCompany.customFields}';
|
//return 'Custom fields [UI]: ${uiState.settingsUIState.userCompany.company.customFields}, [DB] ${selectedCompany.customFields}';
|
||||||
return 'custom fields: ${uiState.settingsUIState.userCompany.company.customFields}';
|
return 'color: ${uiState.accentColor}';
|
||||||
//return 'defaultInvoiceDesignId: ${selectedCompany.settings.defaultInvoiceDesignId}';
|
//return 'defaultInvoiceDesignId: ${selectedCompany.settings.defaultInvoiceDesignId}';
|
||||||
//return 'Routes: Current: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
|
//return 'Routes: Current: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
|
||||||
//return 'Route: ${uiState.currentRoute}, Setting Type: ${uiState.settingsUIState.entityType}, Name: ${uiState.settingsUIState.settings.name}, Updated: ${uiState.settingsUIState.updatedAt}';
|
//return 'Route: ${uiState.currentRoute}, Setting Type: ${uiState.settingsUIState.entityType}, Name: ${uiState.settingsUIState.settings.name}, Updated: ${uiState.settingsUIState.updatedAt}';
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,17 @@ import 'package:invoiceninja_flutter/utils/colors.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
|
|
||||||
class FormColorPicker extends StatefulWidget {
|
class FormColorPicker extends StatefulWidget {
|
||||||
const FormColorPicker({this.labelText, this.initialValue, this.onSelected});
|
const FormColorPicker({
|
||||||
|
this.labelText,
|
||||||
|
this.initialValue,
|
||||||
|
this.onSelected,
|
||||||
|
this.showClear = true,
|
||||||
|
});
|
||||||
|
|
||||||
final String labelText;
|
final String labelText;
|
||||||
final String initialValue;
|
final String initialValue;
|
||||||
final Function(String) onSelected;
|
final Function(String) onSelected;
|
||||||
|
final bool showClear;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_FormColorPickerState createState() => _FormColorPickerState();
|
_FormColorPickerState createState() => _FormColorPickerState();
|
||||||
|
|
@ -27,7 +33,7 @@ class _FormColorPickerState extends State<FormColorPicker> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
_textController.text = widget.initialValue;
|
_selectedColor = _textController.text = widget.initialValue;
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,8 +62,7 @@ class _FormColorPickerState extends State<FormColorPicker> {
|
||||||
child: BlockPicker(
|
child: BlockPicker(
|
||||||
pickerColor: color,
|
pickerColor: color,
|
||||||
onColorChanged: (color) {
|
onColorChanged: (color) {
|
||||||
final hex = color.value.toRadixString(16);
|
_pendingColor = convertColorToHexString(color);
|
||||||
_pendingColor = '#' + hex.substring(2, hex.length);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -98,18 +103,23 @@ class _FormColorPickerState extends State<FormColorPicker> {
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Container(
|
GestureDetector(
|
||||||
color: convertHexStringToColor(widget.initialValue),
|
onTap: _showPicker,
|
||||||
width: 100,
|
child: Container(
|
||||||
height: 20,
|
decoration: BoxDecoration(
|
||||||
|
color: widget.initialValue == null
|
||||||
|
? Colors.grey
|
||||||
|
: convertHexStringToColor(widget.initialValue),
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.black38,
|
||||||
),
|
),
|
||||||
SizedBox(width: 20),
|
),
|
||||||
if (_selectedColor == null)
|
width: 100,
|
||||||
IconButton(
|
height: 25,
|
||||||
icon: Icon(Icons.color_lens),
|
),
|
||||||
onPressed: _showPicker,
|
),
|
||||||
)
|
SizedBox(width: 10),
|
||||||
else
|
if (widget.showClear && _selectedColor != null)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.clear),
|
icon: Icon(Icons.clear),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|
@ -119,7 +129,12 @@ class _FormColorPickerState extends State<FormColorPicker> {
|
||||||
});
|
});
|
||||||
widget.onSelected(null);
|
widget.onSelected(null);
|
||||||
},
|
},
|
||||||
),
|
)
|
||||||
|
else
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.color_lens),
|
||||||
|
onPressed: _showPicker,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ class _DeviceSettingsState extends State<DeviceSettings> {
|
||||||
FormColorPicker(
|
FormColorPicker(
|
||||||
labelText: localization.accentColor,
|
labelText: localization.accentColor,
|
||||||
initialValue: uiState.accentColor,
|
initialValue: uiState.accentColor,
|
||||||
|
showClear: false,
|
||||||
onSelected: (value) =>
|
onSelected: (value) =>
|
||||||
viewModel.onAccentColorChanged(context, value),
|
viewModel.onAccentColorChanged(context, value),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ class DeviceSettingsVM {
|
||||||
AppBuilder.of(context).rebuild();
|
AppBuilder.of(context).rebuild();
|
||||||
},
|
},
|
||||||
onAccentColorChanged: (BuildContext context, String value) async {
|
onAccentColorChanged: (BuildContext context, String value) async {
|
||||||
|
value ??= kDefaultAccentColor;
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
prefs.setString(kSharedPrefAccentColor, value);
|
prefs.setString(kSharedPrefAccentColor, value);
|
||||||
store.dispatch(UserSettingsChanged(accentColor: value));
|
store.dispatch(UserSettingsChanged(accentColor: value));
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,14 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
Color convertHexStringToColor(String value) {
|
Color convertHexStringToColor(String value) {
|
||||||
if (value == null)
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
value = value.replaceAll('#', '');
|
value = value.replaceAll('#', '');
|
||||||
return Color(int.parse(value, radix: 16) + 0xFF000000);
|
return Color(int.parse(value, radix: 16) + 0xFF000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String convertColorToHexString(Color color) {
|
||||||
|
final hex = color.value.toRadixString(16);
|
||||||
|
return '#' + hex.substring(2, hex.length);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue