0

I am getting this error message. error:

The instance member '_endeks' can't be accessed in an initializer. There is no error when I write the list directly. But I want to make as a argument. How can i fix this problem? Can you help me?

import 'package:flutter/material.dart';
import 'ana_sayfa.dart';
import 'alim_satim.dart';
import 'package:trade_online/e_takvim.dart';
import 'haberler.dart';
import 'piyasalar.dart';

class _BottomNavigationBar_bymeState extends State<BottomNavigationBar_byme> {
  
  IconThemeData ikonrengi = IconThemeData(
    color: Color.fromRGBO(180, 177, 168, 1),
  );
  List<String> dizi = <String>["Son", "%Fark", "Fark", "Düşük"];
  List<String> _endeks=["XAG/TR","XAG/USD","USD/TR","XAU/TR","EURO/TR"];
  int _selectedIndex = 0;
   List<Widget> _pages = [
    HomePage(true, _endeks),// "_endeks" Error in here dear friends.
    PiyasalarSayfasi(),
    Haberler(),
    E_Takvim(),
    Alim_Satim_Sign()
  ];
}

1 Answers1

0

You are getting this error because you are doing the equivalent of this

class A {
  int x;
  int y = x;
}

Where you are using a property in the initialization of another.

Simply copy the list instead of referencing it like so

List<String> _endeks= const ["XAG/TR","XAG/USD","USD/TR","XAU/TR","EURO/TR"];

then in _pages

HomePage(true,  const ["XAG/TR","XAG/USD","USD/TR","XAU/TR","EURO/TR"]),

And make sure to mutate _pages when _endeks changes.

moneer alhashim
  • 800
  • 4
  • 11