I have a case where I have to send the ID parameter to another page, and on another page I have to receive the ID that was sent on the first page.
on the first page I have API data in the form of a list and each card/data has a different ID, when the user chooses card A then what is sent is ID A and on another page must receive ID A, if the user chooses card B then what is sent is ID B and on other pages must accept ID B
i have two API
first the API data is a list and I want to send this ID.
and this is the second API where when accessing this API an ID must be sent.
how do i make the ID reusable without having to type it in the API because this code is hardcore code how do i make it so that when the user selects another card it automatically displays a different ID based on the user’s choice.
I’m confused here
page one
page two detail (get ID in page one)
Future<ModelAbsensi> getDetailAbs() async {
String url = Constant.baseURL;
String token = await UtilSharedPreferences.getToken();
final response = await http.get(
Uri.parse(
'$url/auth/mhs_siakad/absensi_perkuliahan?id_kelas_kuliah=c92f49f7-cabf-423a-bfa5-ae798a3048d9',
),
headers: {
'Authorization': 'Bearer $token',
},
);
print('${response.statusCode}');
print(response.body);
if (response.statusCode == 200) {
final result = json.decode(response.body) as Map<String, dynamic>;
Data detailKurikulum = Data.fromJson(result);
ModelAbsensi? l = detailKurikulum.mataKuliah as ModelAbsensi?;
return l!;
} else {
throw Exception();
}
}
button click
SizedBox(
width: double.infinity,
height: 38,
child: TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: ((context) {
return DetailAbsensi(
jadwal: post,
);
}),
settings: RouteSettings(
arguments: todos,
),
),
);
},
style: TextButton.styleFrom(
backgroundColor: const Color(0xffC9F7F5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
"Absensi",
style: bold5.copyWith(
color: const Color(
0xff1BC5BD,
),
),
),
),
),
2
Answers
Check out how data can be passed from one page to another here
https://docs.flutter.dev/cookbook/navigation/passing-data
follow this exmaple:
you can run it on : https://dartpad.dev/