macOS widgets
This commit is contained in:
parent
95fc7a59d1
commit
4bddd3ff8c
|
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/company_model.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/static/currency_model.dart';
|
||||
import 'package:invoiceninja_flutter/main_app.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
|
|
@ -139,10 +140,8 @@ class WidgetCompany {
|
|||
userCompanyState.clientState.map,
|
||||
userCompanyState.groupState.map,
|
||||
).where((currencyId) => currencyId != kCurrencyAll))
|
||||
currencyId: WidgetCurrency(
|
||||
id: currencyId,
|
||||
name: staticState.currencyMap[currencyId].name,
|
||||
exchangeRate: staticState.currencyMap[currencyId].exchangeRate,
|
||||
currencyId: WidgetCurrency.fromCurrency(
|
||||
staticState.currencyMap[currencyId],
|
||||
)
|
||||
};
|
||||
|
||||
|
|
@ -172,20 +171,34 @@ class WidgetCompany {
|
|||
}
|
||||
|
||||
class WidgetCurrency {
|
||||
WidgetCurrency({this.id, this.name, this.exchangeRate});
|
||||
WidgetCurrency({
|
||||
this.id,
|
||||
this.name,
|
||||
this.code,
|
||||
this.exchangeRate,
|
||||
});
|
||||
|
||||
WidgetCurrency.fromCurrency(CurrencyEntity currency)
|
||||
: id = currency.id,
|
||||
name = currency.name,
|
||||
code = currency.code,
|
||||
exchangeRate = currency.exchangeRate;
|
||||
|
||||
WidgetCurrency.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
name = json['name'],
|
||||
code = json['code'],
|
||||
exchangeRate = json['exchange_rate'];
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'id': id,
|
||||
'name': name,
|
||||
'code': code,
|
||||
'exchange_rate': exchangeRate,
|
||||
};
|
||||
|
||||
final String id;
|
||||
final String name;
|
||||
final String code;
|
||||
final double exchangeRate;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ struct Provider: IntentTimelineProvider {
|
|||
|
||||
func getTimeline(for configuration: ConfigurationIntent,
|
||||
in context: Context,
|
||||
completion: @escaping (Timeline<Entry>) -> ()) {
|
||||
|
||||
completion: @escaping (Timeline<Entry>) -> ()) {
|
||||
|
||||
print("## getTimeline")
|
||||
|
||||
Task {
|
||||
|
|
@ -169,11 +169,13 @@ struct WidgetCompany: Decodable, Hashable {
|
|||
struct WidgetCurrency: Decodable, Hashable {
|
||||
let id: String
|
||||
let name: String
|
||||
let code: String
|
||||
let exchangeRate: Double
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case code
|
||||
case exchangeRate = "exchange_rate"
|
||||
}
|
||||
}
|
||||
|
|
@ -190,31 +192,32 @@ struct DashboardWidgetEntryView : View {
|
|||
var entry: Provider.Entry
|
||||
|
||||
var body: some View {
|
||||
//Text(entry.widgetData?.tokens.keys.joined() ?? "BLANK")
|
||||
//Text("TEST \(entry.configuration.field.rawValue)")
|
||||
VStack {
|
||||
//Text(entry.configuration.company?.identifier ?? "")
|
||||
Text(entry.field)
|
||||
Text("Value: \(entry.value)")
|
||||
Text(entry.configuration.company?.displayString ?? "")
|
||||
Text(entry.widgetData?.url ?? "")
|
||||
}
|
||||
|
||||
/*
|
||||
ZStack {
|
||||
Rectangle().fill(BackgroundStyle())
|
||||
VStack(alignment: .leading) {
|
||||
Text("Balance")
|
||||
.font(.largeTitle)
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(Color.blue)
|
||||
Text("$123.00")
|
||||
.privacySensitive()
|
||||
.font(.title2)
|
||||
.foregroundColor(Color.gray)
|
||||
}
|
||||
//Text(entry.widgetData?.tokens.keys.joined() ?? "BLANK")
|
||||
//Text("TEST \(entry.configuration.field.rawValue)")
|
||||
VStack {
|
||||
//Text(entry.configuration.company?.identifier ?? "")
|
||||
Text(entry.field)
|
||||
Text("Value: \(entry.value)")
|
||||
Text(entry.configuration.company?.displayString ?? "")
|
||||
Text(entry.widgetData?.url ?? "")
|
||||
}
|
||||
*/
|
||||
|
||||
ZStack {
|
||||
Rectangle().fill(BackgroundStyle())
|
||||
VStack(alignment: .leading) {
|
||||
Text(entry.field)
|
||||
.font(.body)
|
||||
.bold()
|
||||
.foregroundColor(Color.blue)
|
||||
Text("\(entry.value)")
|
||||
.font(.title)
|
||||
.privacySensitive()
|
||||
.foregroundColor(Color.gray)
|
||||
.minimumScaleFactor(0.8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -331,12 +334,12 @@ struct ApiService {
|
|||
do {
|
||||
let (data, _) = try await URLSession.shared.data(for: request)
|
||||
// process data
|
||||
|
||||
|
||||
//print("## Details: \(String(describing: String(data: data, encoding: .utf8)))")
|
||||
let result = try JSONDecoder().decode([String: ApiResult].self, from: data)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
} catch {
|
||||
print("Error: \(error)")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue