business

import SwiftUI

struct Product: Identifiable { let id = UUID() let name: String let pricePerKg: Double }

struct ContentView: View { @State private var selectedProduct: Product? @State private var quantity: Double = 1.0 @State private var orderDate = Date() @State private var showingConfirmation = false

let products = [
    Product(name: "Lamb", pricePerKg: 15.0),
    Product(name: "Beef", pricePerKg: 20.0),
    Product(name: "Chicken", pricePerKg: 10.0)
]

var body: some View {
    NavigationView {
        Form {
            Section(header: Text("Select Meat")) {
                Picker("Meat Type", selection: $selectedProduct) {
                    ForEach(products) { product in
                        Text(product.name).tag(product as Product?)
                    }
                }
            }

            if let selectedProduct = selectedProduct {
                Section(header: Text("Quantity (kg)")) {
                    Stepper(value: $quantity, in: 0.5...10, step: 0.5) {
                        Text("\(quantity, specifier: "%.1f") kg")
                    }
                }

                Section(header: Text("Delivery Date")) {
                    DatePicker("Select Date", selection: $orderDate, in: Date()..., displayedComponents: .date)
                }

                Section(header: Text("Total Price")) {
                    Text("$\(selectedProduct.pricePerKg * quantity, specifier: "%.2f")")
                }

                Button("Confirm Order") {
                    showingConfirmation = true
                }
                .alert(isPresented: $showingConfirmation) {
                    Alert(title: Text("Order Confirmed"), message: Text("You have ordered \(quantity, specifier: "%.1f") kg of \(selectedProduct.name) for \(orderDate.formatted(date: .long, time: .omitted))."), dismissButton: .default(Text("OK")))
                }
            }
        }
        .navigationTitle("Halal Butcher")
    }
}

}

@main struct HalalButcherApp: App { var body: some Scene { WindowGroup { ContentView() } } }

What's your question?

Posting code without giving us any clue as to why, is just bonkers.

@sabdi7676 We do not have enough information to understand the issue you're having. Can you provide more context on the issue you're having?

For additional tips on creating Apple Developer Forums posts, see tips on writing forums posts.

business
 
 
Q