Facebook
From Caique Alves, 3 Years ago, written in Dart.
Embed
Download Paste or View Raw
Hits: 53
  1. import 'dart:convert';
  2.  
  3. import 'package:flutter_spinkit/flutter_spinkit.dart';
  4. import 'package:singlecheff/consts/consts.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:singlecheff/functions/fn_business.dart';
  7. import 'package:singlecheff/functions/fn_utils.dart';
  8.  
  9. class CategoriasViewPage extends StatefulWidget {
  10.   CategoriasViewPage({Key key, this.title})
  11.       : super(key: key);
  12.  
  13.   final String title;
  14.  
  15.   @override
  16.   _CategoriasViewPage createState() => new _CategoriasViewPage();
  17. }
  18.  
  19. class _CategoriasViewPage extends State<CategoriasViewPage> {
  20.   String url;
  21.  
  22.   @override
  23.   void initState() {
  24.     url = prefs.getString('serverHost') + 'listar_grupos';
  25.     super.initState();
  26.   }
  27.  
  28.   @override
  29.   Widget build(BuildContext context) {
  30.     return new Scaffold(
  31.       appBar: new AppBar(
  32.         title: Text("Categorias"),
  33.         backgroundColor: secondColor,
  34.         leading: IconButton(
  35.           icon: const Icon(Icons.arrow_back_ios),
  36.           onPressed: () {
  37.             confirmarVoltarParaControles(context);
  38.           },
  39.         ),
  40.       ),
  41.       body: FutureBuilder(
  42.         future: fetchData(url).then((response) {
  43.           return jsonDecode(response.body)['Data'];
  44.         }),
  45.         builder: (context, snapshot) {
  46.           if (snapshot.data != null) {
  47.             List<dynamic> result = snapshot.data;
  48.             return Column(
  49.               mainAxisSize: MainAxisSize.max,
  50.               children: [
  51.                 Container(
  52.                   margin: EdgeInsets.only(top: 20, bottom: 20),
  53.                   child: Center(
  54.                     child: Text(
  55.                       controleAtual['descr_controle'],
  56.                       style: TextStyle(fontSize: 20),
  57.                     ),
  58.                   ),
  59.                 ),
  60.                 Container(
  61.                   decoration: BoxDecoration(
  62.                     border: Border(
  63.                       bottom: BorderSide(color: Colors.black12),
  64.                     ),
  65.                   ),
  66.                 ),
  67.                 ListView.builder(
  68.                   scrollDirection: Axis.vertical,
  69.                   shrinkWrap: true,
  70.                   itemCount: result.length,
  71.                   itemBuilder: (context, index) {
  72.                     return Container(
  73.                       margin: defaultMargin20,
  74.                       decoration: BoxDecoration(
  75.                         border: Border(
  76.                           bottom: BorderSide(color: Colors.black12),
  77.                         ),
  78.                       ),
  79.                       child: ListTile(
  80.                         leading: Icon(Icons.apps),
  81.                         title: Text(result[index]['gru_descricao']),
  82.                         onTap: () {
  83.                           grupoAtual = result[index]['gru_id'];
  84.                           Navigator.of(context).pushNamed("/subcategorias");
  85.                         },
  86.                       ),
  87.                     );
  88.                   },
  89.                 )
  90.               ],
  91.             );
  92.           } else {
  93.             return SpinKitDualRing(
  94.               color: secondColor,
  95.               size: 50.0,
  96.             );
  97.           }
  98.         },
  99.       ),
  100.     );
  101.   }
  102. }
  103.