import SwiftUI
struct PokemonDetailView: View {
@EnvironmentObject var vm: ViewModel
let pokemon: Pokemon
var body: some View {
VStack {
PokemonView(pokemon: pokemon)
VStack(spacing: 10) {
Text("ID: (vm.pokemonDetails?.id ?? 0)")
Text("Weight: (vm.formatHW(value: vm.pokemonDetails?.weight ?? 0)) KG")
Text("Height: ((vm.formatHW(value: vm.pokemonDetails?.height ?? 0)) M")
}
.padding()
}
.onAppear {
vm.getDetails(pokemon: pokemon)
}
}
}
struct PokemonDetailView_Previews: PreviewProvider {
static var previews: some View {
PokemonDetailView(pokemon: Pokemon.samplePokemon)
.environmentObject(ViewModel())
}
}
Post
Replies
Boosts
Views
Activity
import SwiftUI
struct PokemonDetailView: View {
@EnvironmentObject var vm: ViewModel
let pokemon: Pokemon
var body: some View {
VStack {
PokemonView(pokemon: pokemon)
VStack(spacing: 10) {
Text("ID: (vm.pokemonDetails?.id ?? 0)")
Text("Weight: (vm.formatHW(value: vm.pokemonDetails?.weight ?? 0)) KG")
Text("Height: ((vm.formatHW(value: vm.pokemonDetails?.height ?? 0)) M")
}
.padding()
}
.onAppear {
vm.getDetails(pokemon: pokemon)
}
}
}
struct PokemonDetailView_Previews: PreviewProvider {
static var previews: some View {
PokemonDetailView(pokemon: Pokemon.samplePokemon)
.environmentObject(ViewModel())
}
}
"error message" :
in line: Text("ID: (vm.pokemonDetails?.id ?? 0)")
Text("Weight: (vm.formatHW(value: vm.pokemonDetails?.weight ?? 0)) KG")
Text("Height: ((vm.formatHW(value: vm.pokemonDetails?.height ?? 0)) M")
"Cannot call value of non-function type 'Binding'
Referencing subscript 'subscript(dynamicMember:)' requires wrapper 'EnvironmentObject.Wrapper'
insert '$'
Value of type 'ViewModel' has no dynamic member 'formatHW' using key path from root type 'ViewModel'"