Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:xxx/models/user.dart';
- import 'package:xxx/utils/utils.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- class fattureCercaGrid extends StatefulWidget {
- @override
- State<StatefulWidget> createState() {
- // TODO: implement createState
- return _fattureCercaGrid();
- }
- }
- class _fattureCercaGrid extends State<fattureCercaGrid> {
- User user;
- SharedPreferences sharedPrefs;
- var bpActive = <bool>[];
- Future<Null> getData() async {
- Utils.zlog("dentro getData fattureCerca");
- this.user = await new User();
- await this.user.retrieveData();
- Utils.zlog("preso l'utente");
- Utils.zlog(user.bpList);
- bpActive = List.filled(user.bpList.length, false);
- this.sharedPrefs = await SharedPreferences.getInstance();
- Utils.zlog("esco da getDat2a");
- }
- @override
- Widget build(BuildContext context) {
- // TODO: implement build
- return FutureBuilder(
- future: getData(),
- builder: (context, AsyncSnapshot<SharedPreferences> snapshot) {
- Utils.zlog("dentro _fatturePageState::builder");
- Utils.zlog(snapshot);
- switch (snapshot.connectionState) {
- case ConnectionState.done:
- // get the tile number from the shared preference instance
- // stored in snapshot.data
- return _realBody(context);
- break;
- default:
- return Text("Loading...");
- }
- });
- }
- _realBody(BuildContext context) {
- return Flexible(
- child: GridView.count(
- childAspectRatio: 3,
- padding: EdgeInsets.all(10.0),
- crossAxisCount: 2,
- crossAxisSpacing: 18,
- mainAxisSpacing: 18,
- children: this.user.bpList.map<Widget>(_creaBox).toList(),
- )
- );
- }
- Widget _creaBox(bp) {
- return Container(
- decoration: BoxDecoration(
- border: Border.all(color: Colors.grey)),
- child: FlatButton(
- color: Colors.white,
- child: Column(
- children: <Widget> [
- SizedBox(height: 10,),
- Text("nome proprietario"),
- Text(bp['id']),
- ],
- ),
- onPressed: () {
- Utils.zlog("onPressed -> active");
- Utils.zlog(bpActive[0]);
- setState(() {
- Utils.zlog("onPressed -> active dopo");
- bpActive[0] = true;
- });
- },
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement