I followed provider and get_it tutorial and used in my projects.
I have encountered an issue passing data from services to models. May you help me to check my problem.
I have tried it in many ways
goals_view_service.dart
import 'dart:convert';
import 'package:requests/requests.dart';
// goal_data={
// [
// 'goal_name': savings_goal[1],
// 'amount': savings_goal[2],
// 'duration': savings_goal[3],
// ]
// }
class GoalViewServices{
// List<GoalsModel> _goals;
var goals = List<GoalsModel>();
Future<Map<String, dynamic>> _getGoals() async {
Response request;
try {
request = await Requests.get(
url + '/savings_goal_display',
headers: {'content-type': 'application/json'},
// TODO: when having true ssl certificate, change verify to true.
// verify: false,
timeoutSeconds: 20,
);
} catch (e) {
return {"result": "Connection Error: $e"};
}
if (!request.hasError) {
try {
return request.json() as Map<String, dynamic>;
} catch (e) {
return {"result": "$e"};
}
} else {
return {"result": "Unknown Request Error"};
}
}
Future<List<GoalsModel>> renewDataForView() async {
var dic = await _getGoals();
// var goals = List<GoalsModel>();
if (dic != null) {
// print(dic);
// final savingsGoalsDic = dic['saving_goals'];
final savingsGoalsDicArray = List<Map<String, dynamic>>.from(dic['savings_goals'] ?? {}) ?? [];
// final savingsGoalsDicArray = (dic['savings_goals'] ?? {}) ?? [];
print('savingsGoalsDic__: $savingsGoalsDicArray');
for (final aData in savingsGoalsDicArray) {
// print(aData);
// Map json = jsonDecode(aData);
// var title = aData["goal_name"];
// var totalAmount = aData["amount"];
// var durations = aData["duration"];
goals.add(GoalsModel.fromJson(aData));
}
}
// print(goals);
return goals;
}
}
[Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel']
Hi,
I followed provider and get_it tutorial and used in my projects. I have encountered an issue passing data from services to models. May you help me to check my problem. I have tried it in many ways
goals_view_service.dart
goals_model.dart
Goals_viewmodels.dart
Goals Dictionary
savingsGoalsDic__: [{amount: 123, duration: 3, goal_name: Car}, {amount: 123, duration: 2, goal_name: Housing}, {amount: 0, duration: 5, goal_name: Retirement}, {amount: 0, duration: 2, goal_name: Shopping}, {amount: 0, duration: 2, goal_name: Travel}, {amount: 12, duration: 3, goal_name: Wedding}]
Result from Goals_model
[Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel', Instance of 'GoalsModel']