parhorboo

profile.dart

Apr 10th, 2020
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:ospek_unai/profilmodel.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6. import 'package:http/http.dart' as http;
  7.  
  8. class ProfilePage extends StatefulWidget {
  9. @override
  10. _ProfilePageState createState() => _ProfilePageState();
  11. }
  12. class _ProfilePageState extends State<ProfilePage> {
  13. String nomorindukMahasiswa = "";
  14. var loading = false;
  15.  
  16. getPref() async {
  17. SharedPreferences preferences = await SharedPreferences.getInstance();
  18. setState(() {
  19. nomorindukMahasiswa = preferences.getString("nomorindukMahasiswa");
  20. });
  21. }
  22.  
  23.  
  24. final list = new List<ProfilModel>();
  25. _lihatData() async{
  26. list.clear();
  27. setState(() {
  28. loading = true;
  29. });
  30. final response = await http.get("http://10.0.2.2/aplikasi_ospekunai/profil.php?nomorindukMahasiswa=$nomorindukMahasiswa");
  31. if (response.contentLength == 2) {
  32.  
  33. }else {
  34. final data = jsonDecode(response.body);
  35. data.forEach((api){
  36. final ab = new ProfilModel(api['nomorindukMahasiswa'], api['namamahasiswa_ospek'], api['namagroup'], api['foto']);
  37. list.add(ab);
  38. });
  39. setState(() {
  40. loading = false;
  41. });
  42.  
  43. }
  44. }
  45.  
  46.  
  47. @override
  48. void initState() {
  49.  
  50. super.initState();
  51. getPref();
  52. _lihatData();
  53. }
  54. @override
  55. Widget build(BuildContext context) {
  56. return Scaffold(
  57. appBar: AppBar(
  58. title: new Center(child: new Text("Profile Page",textAlign: TextAlign.center,)),
  59. ),
  60. body: loading? Center(child: CircularProgressIndicator()) : ListView.builder(
  61. itemBuilder: (context,i){
  62. final x = list[i];
  63. return Container(
  64. padding: EdgeInsets.all(10),
  65. child: Column(
  66. crossAxisAlignment: CrossAxisAlignment.start,
  67. children: <Widget>[
  68. Text(x.namamahasiswaospek, style: TextStyle(fontSize:12.0, fontWeight: FontWeight.bold),),
  69. Text(x.nomorindukMahasiswa),
  70. Text(x.namagroup),
  71. new Image.network("http://10.0.2.2/aplikasi_ospekunai/foto/${x.foto}")
  72. ],
  73. ),
  74. );
  75. },
  76. )
  77.  
  78.  
  79. );
  80. }
  81. }
Add Comment
Please, Sign In to add comment