Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.03 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:educ_app/models/user.dart';
  4. import 'package:flutter/foundation.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_secure_storage/flutter_secure_storage.dart';
  7.  
  8. import 'package:http/http.dart' as http;
  9.  
  10. //aluno_frequencia_screen
  11.  
  12.  
  13. class aluno_frequencia_screen extends StatefulWidget {
  14.   @override
  15.   _HomeTabState createState() => _HomeTabState();
  16. }
  17.  
  18.  
  19. class _HomeTabState extends State<aluno_frequencia_screen> {
  20.  
  21.   Resp2 resp2;
  22.   bool hasData = false;
  23.  
  24.   final storage = new FlutterSecureStorage();
  25.   @override
  26.   void initState() {
  27.     super.initState();
  28.     getJSONData();
  29.   }
  30.  
  31.   lerToken() async{
  32.     String s = await storage.read(key: "protectToken");
  33.     return s;
  34.  
  35.   }
  36.  
  37.   getJSONData() async {
  38.     var token = await lerToken();
  39.     //var teste = token.replaceAll(new RegExp('""'),'');
  40.     print(token);
  41.  
  42.     var response = await http.get(
  43.         Uri.encodeFull(
  44.             "http://treinamento.educ.ifrn.edu.br/api/educ/diario/1410/"),
  45.         //headers: {"Authorization": "Token dfba99dbad894452f843d1af00ffbcd559c63e59"
  46.         headers: {"Authorization": "Token ${token}"
  47.  
  48.         });
  49.  
  50.     print('Response status: ${response.statusCode}');
  51.     //print('Response body: ${response.body}');
  52.  
  53.     Map userMap = jsonDecode(response.body);
  54.     resp2 = Resp2.fromJson(userMap["result"][0]);
  55.     print(resp2.situacao);
  56.  
  57.     setState(() {
  58.       Map userMap = jsonDecode(response.body);
  59.       resp2 = Resp2.fromJson(userMap["result"][0]);
  60.       hasData = true;
  61.     });
  62.  
  63.     //  List<User> users = userMap['result'].map<User>((json)=>
  64.     //     User.fromJson(json),
  65.     //  ).toList();
  66.     // print(users.toString());
  67.   }
  68.  
  69.  
  70.  
  71.   Widget _buildBodyBack() => Container(
  72.     decoration: BoxDecoration(
  73.         gradient: LinearGradient(colors: [
  74.           Color.fromARGB(255, 51, 55, 232),
  75.           Color.fromARGB(255, 56, 113, 255),
  76.         ], begin: Alignment.topLeft, end: Alignment.bottomRight)),
  77.   );
  78.  
  79.   @override
  80.   Widget build(BuildContext context) {
  81.  
  82.     return
  83.       //(!hasData)
  84.           //? CircularProgressIndicator()
  85.           //:
  86.  
  87.       Scaffold(
  88.  
  89.  
  90.         //_buildBodyBack(),
  91.     //Onde deixa o item fixo no Scroll
  92.  
  93.         appBar: AppBar(
  94.           title: Text("Alunos Diário"),
  95.           centerTitle: true,
  96.         ),
  97.  
  98.         body:
  99.         DataTable(
  100.           columns: [
  101.             DataColumn(
  102.                 label: Text('Aluno',
  103.                     style: TextStyle(fontSize: 20))),
  104.             DataColumn(
  105.                 label: Text('Diário',
  106.                     overflow: TextOverflow.ellipsis,
  107.                     style: TextStyle(fontSize: 20))),
  108.             DataColumn(
  109.                 label: Text('Faltas',
  110.                     style: TextStyle(fontSize: 20))),
  111.             DataColumn(
  112.                 label: Text('Série',
  113.                     style: TextStyle(fontSize: 20))),
  114.             DataColumn(
  115.                 label: Text('Situação',
  116.                     style: TextStyle(fontSize: 20))),
  117.  
  118.           ],
  119.           rows: <DataRow>[
  120.             DataRow(cells: [
  121.               DataCell(Text(
  122.                 resp2.aluno.text,
  123.                 style: TextStyle(color: Colors.white),
  124.  
  125.               ),
  126.                   //onTap:()=> Navigator.push(context,
  127.                      // MaterialPageRoute(builder: (contex) => aluno_frequencia_screen()))
  128.               ),
  129.               DataCell(Text(
  130.                 resp2.diario.text,
  131.                 style: TextStyle(color: Colors.white),
  132.               )),
  133.               DataCell(Text(
  134.                 resp2.get_qtd_faltas.toString(),
  135.                 style: TextStyle(color: Colors.white),
  136.               )),
  137.               DataCell(Text(
  138.                 resp2.get_serie.text,
  139.                 style: TextStyle(color: Colors.white),
  140.               )),
  141.               DataCell(Text(
  142.                 resp2.situacao,
  143.                 style: TextStyle(color: Colors.white),
  144.               )),
  145.  
  146.             ])
  147.           ],
  148.         ),
  149.       );
  150.  
  151.  
  152.   }
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement