Can't fetch Data using withClass

Trying to fetch data using withClass but it call catch clause.

here is my code:
model:

@reflector
class Movie{

  String _name;
  String _type;
  String _channel;
  String _day;
  String _hour;
  String _minutes;
  String _ampm;
  String _url;
  String _plot;

  String get name => _name;

  String get type => _type;

  String get plot => _plot;

  String get url => _url;

  String get ampm => _ampm;

  String get minutes => _minutes;

  String get hour => _hour;

  String get day => _day;

  String get channel => _channel;

}

fetch data :

final DataQueryBuilder queryBuilder = DataQueryBuilder();

  Future<List<Movie>> getData() async {
    queryBuilder.pageSize = 50;

    try {
      var list = await Backendless.data.withClass<Movie>().find(queryBuilder);
      return list;
    }
    catch (e) {
      print("error");
    }
    return [];
  }

note: it works fine using data.of(tablenameā€™)

Hi @peter_estafanos

Please follow the steps described here:

Make sure to call the command

flutter packages pub run build_runner build

After class creation.

If the problem persists please provide the stacktrace of the error you get.

Best Regards,
Maksym

the problem still presists.
this is the error message:

Performing hot restartā€¦
Syncing files to device D6633ā€¦
Restarted application in 2,527ms.
I/art ( 3445): Background sticky concurrent mark sweep GC freed 198984(9MB) AllocSpace objects, 40(1276KB) LOS objects, 36% free, 17MB/28MB, paused 381us total 116.029ms
I/flutter ( 3445): error
I/flutter ( 3445): error
I/flutter ( 3445): error
I/flutter ( 3445): error
I/flutter ( 3445): error
I/flutter ( 3445): error
I/flutter ( 3445): error
I/flutter ( 3445): error

Please change your code to the following

try {
  var list = await Backendless.data.withClass<Movie>().find(queryBuilder);
  return list;
}
catch (e) {
  print(e);
}
return [];

And provide the stacktrace once again.

This is the error message:

I/flutter (26899): type ā€˜MethodMirrorImplā€™ is not a subtype of type ā€˜VariableMirrorā€™
I/flutter (26899): type ā€˜MethodMirrorImplā€™ is not a subtype of type ā€˜VariableMirrorā€™
I/example.newtes(26899): Background young concurrent copying GC freed 16905(1086KB) AllocSpace objects, 6(168KB) LOS objects, 33% free, 2544KB/3818KB, paused 5.929ms total 82.336ms
I/flutter (26899): type ā€˜MethodMirrorImplā€™ is not a subtype of type ā€˜VariableMirrorā€™
I/flutter (26899): type ā€˜MethodMirrorImplā€™ is not a subtype of type ā€˜VariableMirrorā€™

Hi @peter_estafanos

There is a requirement:

  • The class must contain public fields (or setters) with the names that match the names of the columns in the database.

It is necessary to set the values for the created object.

So make sure your class contains public fields or public setters and getters for them.

Best Regards,
Maksym

I have been searching for 2 days for a solution for this problem but I got nothing.

here is my model it has setters and getter but it still give me error

my model:

import 'package:backendless_sdk/backendless_sdk.dart';

@reflector
class Movie{

  var _name;
  var _type;
  var _channel;
  var _day;
  var _hour;
  var _minutes;
  var _ampm;
  var _url;
  var _plot;

  get name => _name;

  get type => _type;

  get channel => _channel;

  get day => _day;

  get hour => _hour;

  get minutes => _minutes;

  get ampm => _ampm;

  get url => _url;

  get plot => _plot;

  set plot(value) {
    _plot = value;
  }

  set url(value) {
    _url = value;
  }

  set ampm(value) {
    _ampm = value;
  }

  set minutes(value) {
    _minutes = value;
  }

  set hour(value) {
    _hour = value;
  }

  set day(value) {
    _day = value;
  }

  set channel(value) {
    _channel = value;
  }

  set type(value) {
    _type = value;
  }

  set name(value) {
    _name = value;
  }
}

the error message :
I/flutter (30839): type 'MethodMirrorImpl' is not a subtype of type 'VariableMirror'

note: it works fine using data.of(tablenameā€™)

I solved it, I forgot to add no-argument constructor.
Now it works just fine.

1 Like

Glad you resolved it. Happy coding with Backendless!

1 Like