onInit method

  1. @override
void onInit()
override

Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.

Implementation

@override
void onInit() {
  httpClient.defaultDecoder = (map) {
    if (map is Map<String, dynamic> && map.containsKey('error')) {
      print('error');
    } else if (map is Map<String, dynamic> &&
        map.containsKey('data') == false) {
      return element.fromJson(map);
    } else if (map is Map<String, dynamic> && map.containsKey('data')) {
      return map['data'].map((item) => element.fromJson(item)).toList();
    }
  };
  super.onInit();
  httpClient.baseUrl = 'http://localhost/api';
}