Home > OS >  The final variable 'champion' must be initialized. Try initializing the variable
The final variable 'champion' must be initialized. Try initializing the variable

Time:11-02

So what I have here is a map with some data, so i want to use some of this tha but when I try to call it on ma DetailScreen this message shows up

class _DetailViewState extends State<DetailView> {
  final Champion champion;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.black45,
        body: Stack(children: [
          Container(
              height: 300, child: Image.asset("images/brimstone-valo.jpg")),

also here is my map example

import 'package:valorant_heros/constants/constant.dart';

class Champion {
  late String name;
  late String nickName;
  late Role role;
  late Difficulty difficulty;
  late String image;
  late String description;

  Champion(
      { required this.name,
       required this.nickName,
       required this.role,
       required this.difficulty,
       required this.image,
       required this.description});
}

var agentMap = {
  "brimstone": Champion(
      name: "Brimstone",
      nickName: "aa",
      role: Role.CONTROLADOR,
      difficulty: Difficulty.FACIL,
      image: "images/brimstone-valo.jpg",
      description:
          'Vindo diretamente dos EUA, o arsenal orbital de Brimstone garante que o esquadrão dele esteja sempre em vantagem. Sua capacidade de oferecer utilidade com precisão a distância faz dele um comandante inigualável na linha de frente.'),
 

CodePudding user response:

You can use constructor to receiving the model. But while it is on state class, you can use late and initialize it before reading.

class _DetailViewStateState extends State<DetailViewState> {
  late final Champion champion;
  • Related