12

I have a class TripController that contains a private field _updatedAccount. I created a getter in order to get from outside.

class TripController {
  final String _accountId;
  final BuildContext _context;
  Account _updatedAccount;  
  Account updatedAccount() => _updatedAccount;


  TripController(this._accountId, this._context);
...
}

In another class, where I perfectly have access to the TripController class, I have the code :

onTap: () {
 TripController _tripController =
 new TripController(_account.id, context);
 _tripController.add(context);
 _account.trips  = _tripController.updatedAccount.trips;
 _account.notifyListeners();
},

And here, updatedAccount from _tripController.updatedAccount.trips is underlined in red with the message : The getter 'updatedAccount' isn't defined for the class 'TripController'

Did I misdeclared the getter ?

user54517
  • 2,020
  • 5
  • 30
  • 47

8 Answers8

5

Okay, I finally fixed it. I don't know why, but I had to delete the code related to TripController, and ther re-write it again. I don't know why, maybe it was an Editor problem, I'm using VScode.

user54517
  • 2,020
  • 5
  • 30
  • 47
  • For me it worked by reloading VS code window. To reload window: `(Cmd/ Ctrl )+Shift+P` and search for reload there should be an option called ```Developer: Reload Window``` Caution: Reloading window will kill the current running terminals / emulators / sessions – StabCode May 05 '22 at 04:13
3

You have declared updatAccount() as a method, not as a getter. Use _tripController.updatedAccount().trips; or change the method to a getter Account get updatedAccount => _updatedAccount;

Tidder
  • 1,126
  • 1
  • 7
  • 15
2

I faced this error and the problem was my IDE, not my code. This solution worked for me in Android Studio :

File -> Invalidate Catches... -> Invalidate And Restart

Ghazal
  • 123
  • 2
  • 9
0

You are using the classic method syntax declaration, in Dart language, prefer using this kind of syntax for getters:

Account get updatedAccount => _updatedAccount;

And call it the way you did. Else you should call it like a classic method:

_tripController.updatedAccount().trips

Please follow this link for further information:

https://dart.dev/guides/language/language-tour#getters-and-setters

0

If you want to use import 'package:flutter_svg/svg.dart'; package then you need to follow these steps.

step 1. -> Open the termial in the IDE and run this command -> flutter pub add flutter_svg

step 2. -> Then run this command -> flutter pub get

step 3. -> Now import this package -> import 'package:flutter_svg/flutter_svg.dart';

0

Try to check the model class name you use might the same with existing name of Widget or Plugin

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 27 '22 at 17:29
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32322487) – MohanKumar Jul 29 '22 at 08:05
0

Check your imported libraries on the top of your file where the problem is. In my case, Android Studio auto-imported an object from the core Flutter library with the same name as the model I've defined on my own.

I just deleted the import and then imported my own object from my_models.dart file.

spehj
  • 1
0

The first thing to do when getting an exception in Flutter - is to restart IDE.

Yuriy N.
  • 4,936
  • 2
  • 38
  • 31