macOS widgets

This commit is contained in:
Hillel Coren 2023-06-22 16:18:14 +03:00
parent 95fc7a59d1
commit 4bddd3ff8c
2 changed files with 47 additions and 31 deletions

View File

@ -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;
}

View File

@ -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,6 +192,7 @@ 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 {
@ -199,22 +202,22 @@ struct DashboardWidgetEntryView : View {
Text(entry.configuration.company?.displayString ?? "")
Text(entry.widgetData?.url ?? "")
}
*/
/*
ZStack {
Rectangle().fill(BackgroundStyle())
VStack(alignment: .leading) {
Text("Balance")
.font(.largeTitle)
.fontWeight(.bold)
Text(entry.field)
.font(.body)
.bold()
.foregroundColor(Color.blue)
Text("$123.00")
Text("\(entry.value)")
.font(.title)
.privacySensitive()
.font(.title2)
.foregroundColor(Color.gray)
.minimumScaleFactor(0.8)
}
}
*/
}
}