Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:ospek_unai/profilmodel.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:http/http.dart' as http;
- class ProfilePage extends StatefulWidget {
- @override
- _ProfilePageState createState() => _ProfilePageState();
- }
- class _ProfilePageState extends State<ProfilePage> {
- String nomorindukMahasiswa = "";
- var loading = false;
- getPref() async {
- SharedPreferences preferences = await SharedPreferences.getInstance();
- setState(() {
- nomorindukMahasiswa = preferences.getString("nomorindukMahasiswa");
- });
- }
- final list = new List<ProfilModel>();
- _lihatData() async{
- list.clear();
- setState(() {
- loading = true;
- });
- final response = await http.get("http://10.0.2.2/aplikasi_ospekunai/profil.php?nomorindukMahasiswa=$nomorindukMahasiswa");
- if (response.contentLength == 2) {
- }else {
- final data = jsonDecode(response.body);
- data.forEach((api){
- final ab = new ProfilModel(api['nomorindukMahasiswa'], api['namamahasiswa_ospek'], api['namagroup'], api['foto']);
- list.add(ab);
- });
- setState(() {
- loading = false;
- });
- }
- }
- @override
- void initState() {
- super.initState();
- getPref();
- _lihatData();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: new Center(child: new Text("Profile Page",textAlign: TextAlign.center,)),
- ),
- body: loading? Center(child: CircularProgressIndicator()) : ListView.builder(
- itemBuilder: (context,i){
- final x = list[i];
- return Container(
- padding: EdgeInsets.all(10),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(x.namamahasiswaospek, style: TextStyle(fontSize:12.0, fontWeight: FontWeight.bold),),
- Text(x.nomorindukMahasiswa),
- Text(x.namagroup),
- new Image.network("http://10.0.2.2/aplikasi_ospekunai/foto/${x.foto}")
- ],
- ),
- );
- },
- )
- );
- }
- }
Add Comment
Please, Sign In to add comment