Advertisement
Guest User

Future Builder

a guest
Apr 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.82 KB | None | 0 0
  1. FutureBuilder<List>(
  2.                       future: GetSchedule().getService(),
  3.                       builder:
  4.                           (BuildContext context, AsyncSnapshot<List> snapshot) {
  5.                         switch (snapshot.connectionState) {
  6.                           case ConnectionState.active:
  7.                           case ConnectionState.none:
  8.                           case ConnectionState.waiting:
  9.                             return Center(
  10.                               child: Padding(
  11.                                 padding:
  12.                                     EdgeInsets.only(top: 16.0, bottom: 16.0),
  13.                                 child: CircularProgressIndicator(),
  14.                               ),
  15.                             );
  16.                             break;
  17.                           case ConnectionState.done:
  18.                             if (!snapshot.hasData) {
  19.                               return SizedBox(
  20.                                 height: 80,
  21.                                 child: Container(
  22.                                   padding:
  23.                                       EdgeInsets.only(top: 8.0, bottom: 8.0),
  24.                                   child: Center(
  25.                                     child: Text(
  26.                                       "Sem serviços disponiveis no momento!",
  27.                                       style: TextStyle(
  28.                                           fontWeight: FontWeight.w200),
  29.                                     ),
  30.                                   ),
  31.                                 ),
  32.                               );
  33.                             } else {
  34.                               return ListView.builder(
  35.                                 shrinkWrap: true,
  36.                                 itemCount: snapshot.data.length,
  37.                                 itemBuilder: (context, index) {
  38.                                   return ListTile(
  39.                                     onTap: () {
  40.                                       setState(() {
  41.                                         service = true;
  42.                                         _service = snapshot.data[index]["id"];
  43.                                         Navigator.of(context).pop();
  44.                                       });
  45.                                     },
  46.                                     leading: CircleAvatar(
  47.                                       radius: 25.0,
  48.                                       backgroundColor: Colors.yellow,
  49.                                       backgroundImage: NetworkImage(snapshot
  50.                                           .data[index]["image"]),
  51.                                     ),
  52.                                     title: Text(
  53.                                       snapshot
  54.                                           .data[index]["name"],
  55.                                       style: TextStyle(
  56.                                           fontWeight: FontWeight.w300),
  57.                                     ),
  58.                                     trailing: Column(
  59.                                       children: <Widget>[
  60.                                         Text(
  61.                                           "R\$${snapshot.data[index]["price"]}",
  62.                                           style: TextStyle(
  63.                                               fontWeight: FontWeight.w300),
  64.                                         ),
  65.                                         Text(
  66.                                             "${snapshot.data[index]["time"]} min")
  67.                                       ],
  68.                                     ),
  69.                                   );
  70.                                 },
  71.                               );
  72.                             }
  73.                         }
  74.                       },
  75.                     ),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement