macOS widgets
This commit is contained in:
parent
d89f126551
commit
0ba0c3f7ec
|
|
@ -1406,25 +1406,8 @@ void _showAbout(BuildContext context) async {
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
final json = jsonEncode(WidgetData(
|
final json = jsonEncode(WidgetData.fromState(state, localization));
|
||||||
url: formatApiUrl(state.authState.url),
|
|
||||||
companyId: state.account.defaultCompanyId,
|
|
||||||
dateRanges: Map.fromIterable(DateRange.values,
|
|
||||||
key: (dynamic item) => toSnakeCase('$item'),
|
|
||||||
value: (dynamic item) =>
|
|
||||||
localization.lookup('$item')),
|
|
||||||
companies: {
|
|
||||||
for (var userCompany in state.userCompanyStates
|
|
||||||
.where((state) => state.company.hasName))
|
|
||||||
userCompany.company.id:
|
|
||||||
WidgetCompany.fromUserCompany(
|
|
||||||
userCompanyState: userCompany,
|
|
||||||
staticState: state.staticState,
|
|
||||||
)
|
|
||||||
}));
|
|
||||||
|
|
||||||
print('## Set Widget Data: $json');
|
print('## Set Widget Data: $json');
|
||||||
|
|
||||||
await UserDefaults.setString(
|
await UserDefaults.setString(
|
||||||
'widget_data', json, 'group.com.invoiceninja.app');
|
'widget_data', json, 'group.com.invoiceninja.app');
|
||||||
await WidgetKit.reloadAllTimelines();
|
await WidgetKit.reloadAllTimelines();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
import 'package:invoiceninja_flutter/constants.dart';
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/company_model.dart';
|
import 'package:invoiceninja_flutter/data/models/company_model.dart';
|
||||||
|
import 'package:invoiceninja_flutter/data/models/dashboard_model.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/static/currency_model.dart';
|
import 'package:invoiceninja_flutter/data/models/static/currency_model.dart';
|
||||||
import 'package:invoiceninja_flutter/main_app.dart';
|
import 'package:invoiceninja_flutter/main_app.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||||
|
|
@ -12,7 +13,9 @@ import 'package:invoiceninja_flutter/redux/company/company_selectors.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/company/company_state.dart';
|
import 'package:invoiceninja_flutter/redux/company/company_state.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
|
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/strings.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:widget_kit_plugin/user_defaults/user_defaults.dart';
|
import 'package:widget_kit_plugin/user_defaults/user_defaults.dart';
|
||||||
import 'package:widget_kit_plugin/widget_kit/widget_kit.dart';
|
import 'package:widget_kit_plugin/widget_kit/widget_kit.dart';
|
||||||
|
|
@ -104,6 +107,22 @@ class WidgetData {
|
||||||
this.dateRanges,
|
this.dateRanges,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
WidgetData.fromState(AppState state, AppLocalization localization)
|
||||||
|
: url = formatApiUrl(state.authState.url),
|
||||||
|
companyId = state.account.defaultCompanyId,
|
||||||
|
companies = {
|
||||||
|
for (var userCompany in state.userCompanyStates
|
||||||
|
.where((state) => state.company.hasName))
|
||||||
|
userCompany.company.id: WidgetCompany.fromUserCompany(
|
||||||
|
userCompanyState: userCompany,
|
||||||
|
staticState: state.staticState,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
dateRanges = Map.fromIterable(
|
||||||
|
DateRange.values.where((value) => value != DateRange.custom),
|
||||||
|
key: (dynamic item) => toSnakeCase('$item'),
|
||||||
|
value: (dynamic item) => localization.lookup('$item'));
|
||||||
|
|
||||||
WidgetData.fromJson(Map<String, dynamic> json)
|
WidgetData.fromJson(Map<String, dynamic> json)
|
||||||
: url = json['url'],
|
: url = json['url'],
|
||||||
companyId = json['company_id'],
|
companyId = json['company_id'],
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,9 @@ struct Provider: IntentTimelineProvider {
|
||||||
|
|
||||||
var dateComponents = calendar.dateComponents([.year, .month, .day], from: Date())
|
var dateComponents = calendar.dateComponents([.year, .month, .day], from: Date())
|
||||||
|
|
||||||
if (dateRange == "today") {
|
if (dateRange == "all") {
|
||||||
|
start = calendar.date(byAdding: .year, value: -100, to: Date())!
|
||||||
|
} else if (dateRange == "today") {
|
||||||
start = calendar.startOfDay(for: Date())
|
start = calendar.startOfDay(for: Date())
|
||||||
} else if (dateRange == "yesterday") {
|
} else if (dateRange == "yesterday") {
|
||||||
start = calendar.date(byAdding: .day, value: -1, to: Date())!
|
start = calendar.date(byAdding: .day, value: -1, to: Date())!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue