Advertisement
ziobudda

Untitled

Jan 6th, 2021
1,432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.59 KB | None | 0 0
  1. import 'package:xxx/models/user.dart';
  2. import 'package:xxx/utils/utils.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6.  
  7. class fattureCercaGrid extends StatefulWidget {
  8.   @override
  9.   State<StatefulWidget> createState() {
  10.     // TODO: implement createState
  11.     return _fattureCercaGrid();
  12.   }
  13.  
  14. }
  15.  
  16. class _fattureCercaGrid extends State<fattureCercaGrid> {
  17.   User user;
  18.   SharedPreferences sharedPrefs;
  19.   var bpActive = <bool>[];
  20.  
  21.   Future<Null> getData() async {
  22.     Utils.zlog("dentro getData fattureCerca");
  23.     this.user = await new User();
  24.     await this.user.retrieveData();
  25.  
  26.     Utils.zlog("preso l'utente");
  27.     Utils.zlog(user.bpList);
  28.  
  29.     bpActive = List.filled(user.bpList.length, false);
  30.  
  31.     this.sharedPrefs = await SharedPreferences.getInstance();
  32.     Utils.zlog("esco da getDat2a");
  33.   }
  34.  
  35.   @override
  36.   Widget build(BuildContext context) {
  37.     // TODO: implement build
  38.     return FutureBuilder(
  39.         future: getData(),
  40.         builder: (context, AsyncSnapshot<SharedPreferences> snapshot) {
  41.           Utils.zlog("dentro _fatturePageState::builder");
  42.           Utils.zlog(snapshot);
  43.           switch (snapshot.connectionState) {
  44.             case ConnectionState.done:
  45.             // get the tile number from the shared preference instance
  46.             // stored in snapshot.data
  47.               return _realBody(context);
  48.               break;
  49.  
  50.             default:
  51.               return Text("Loading...");
  52.           }
  53.         });
  54.   }
  55.  
  56.   _realBody(BuildContext context) {
  57.     return Flexible(
  58.         child: GridView.count(
  59.           childAspectRatio: 3,
  60.           padding: EdgeInsets.all(10.0),
  61.           crossAxisCount: 2,
  62.           crossAxisSpacing: 18,
  63.           mainAxisSpacing: 18,
  64.           children: this.user.bpList.map<Widget>(_creaBox).toList(),
  65.         )
  66.     );
  67.   }
  68.  
  69.   Widget _creaBox(bp) {
  70.     return Container(
  71.         decoration: BoxDecoration(
  72.  
  73.             border: Border.all(color: Colors.grey)),
  74.         child: FlatButton(
  75.           color: Colors.white,
  76.           child: Column(
  77.  
  78.             children: <Widget> [
  79.               SizedBox(height: 10,),
  80.               Text("nome proprietario"),
  81.               Text(bp['id']),
  82.             ],
  83.           ),
  84.           onPressed: () {
  85.             Utils.zlog("onPressed -> active");
  86.             Utils.zlog(bpActive[0]);
  87.             setState(() {
  88.               Utils.zlog("onPressed -> active dopo");
  89.               bpActive[0] = true;
  90.             });
  91.           },
  92.         )
  93.  
  94.     );
  95.   }
  96.  
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement