2023-10-23 17:43:16 -06:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
|
|
// Loads a default image from the flutter assets bundle,
|
2023-10-23 18:06:39 -06:00
|
|
|
// or displays a base64 encoded image that has been saved from the flutter application
|
2023-10-23 17:43:16 -06:00
|
|
|
struct BgImage : View {
|
|
|
|
var entry: WonderousEntry
|
|
|
|
var body: some View {
|
|
|
|
var uiImage:UIImage?;
|
|
|
|
if(entry.imageData.isEmpty){
|
2023-10-23 18:06:39 -06:00
|
|
|
let defaultImage = flutterAssetBundle.appending(path: "/assets/images/widget/background-empty.jpg").path();
|
2023-10-23 17:43:16 -06:00
|
|
|
uiImage = UIImage(contentsOfFile: defaultImage);
|
|
|
|
} else {
|
|
|
|
uiImage = UIImage(data: Data(base64Encoded: entry.imageData)!)
|
|
|
|
}
|
|
|
|
if(uiImage != nil){
|
2023-10-23 18:06:39 -06:00
|
|
|
// Use geometry reader to prevent the image from pushing the other content out of the widgets bounds (https://stackoverflow.com/questions/57593552/swiftui-prevent-image-from-expanding-view-rect-outside-of-screen-bounds)
|
2023-10-23 17:43:16 -06:00
|
|
|
let image = GeometryReader { geometry in
|
|
|
|
Image(uiImage: uiImage!)
|
|
|
|
.resizable()
|
|
|
|
.aspectRatio(contentMode: .fill)
|
|
|
|
.edgesIgnoringSafeArea(.all) // Ignore the safe area
|
|
|
|
.frame(maxWidth: geometry.size.width, maxHeight: geometry.size.height)
|
|
|
|
}
|
|
|
|
return AnyView(image)
|
|
|
|
}
|
2023-10-23 18:06:39 -06:00
|
|
|
debugPrint("The image file could not be loaded")
|
2023-10-23 17:43:16 -06:00
|
|
|
return AnyView(EmptyView())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct GaugeProgressStyle: ProgressViewStyle {
|
|
|
|
func makeBody(configuration: Configuration) -> some View {
|
|
|
|
let fractionCompleted = configuration.fractionCompleted ?? 0
|
|
|
|
|
|
|
|
return ZStack {
|
|
|
|
Circle()
|
|
|
|
.stroke(Colors.darkGrey, style: StrokeStyle(lineWidth: 2))
|
|
|
|
Circle()
|
|
|
|
.trim(from: 0, to: fractionCompleted)
|
|
|
|
.stroke(Colors.accentColor, style: StrokeStyle(lineWidth: 4, lineCap: .round))
|
|
|
|
.rotationEffect(.degrees(90))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|