|
| 1 | +import 'dart:async'; |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter_slidable/flutter_slidable.dart'; |
| 5 | + |
| 6 | +class Data { |
| 7 | + final String url = 'https://via.placeholder.com/350x150'; |
| 8 | +} |
| 9 | + |
| 10 | +void main() => runApp(new MyApp()); |
| 11 | + |
| 12 | +Future<Data> getData() async { |
| 13 | + await Future.delayed(Duration(seconds: 1)); |
| 14 | + return Data(); |
| 15 | +} |
| 16 | + |
| 17 | +class MyApp extends StatelessWidget { |
| 18 | + // This widget is the root of your application. |
| 19 | + @override |
| 20 | + Widget build(BuildContext context) { |
| 21 | + return new MaterialApp( |
| 22 | + title: 'Flutter Slidable Demo', |
| 23 | + theme: new ThemeData( |
| 24 | + primarySwatch: Colors.blue, |
| 25 | + ), |
| 26 | + home: new MyHomePage(title: 'Flutter Slidable Demo'), |
| 27 | + ); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +class MyHomePage extends StatefulWidget { |
| 32 | + MyHomePage({Key key, this.title}) : super(key: key); |
| 33 | + |
| 34 | + final String title; |
| 35 | + |
| 36 | + @override |
| 37 | + _MyHomePageState createState() => new _MyHomePageState(); |
| 38 | +} |
| 39 | + |
| 40 | +class _MyHomePageState extends State<MyHomePage> { |
| 41 | + final SlidableController slidableController = new SlidableController(); |
| 42 | + |
| 43 | + @override |
| 44 | + Widget build(BuildContext context) { |
| 45 | + return new Scaffold( |
| 46 | + appBar: new AppBar( |
| 47 | + title: new Text(widget.title), |
| 48 | + ), |
| 49 | + body: ListView.builder( |
| 50 | + itemCount: 20, |
| 51 | + itemBuilder: (context, index) { |
| 52 | + return FutureBuilder<Data>( |
| 53 | + future: getData(), |
| 54 | + builder: (context, snapshot) { |
| 55 | + if (snapshot.hasData) { |
| 56 | + return Slidable( |
| 57 | + delegate: SlidableScrollDelegate(), |
| 58 | + actionExtentRatio: 0.25, |
| 59 | + secondaryActions: <Widget>[ |
| 60 | + IconSlideAction( |
| 61 | + caption: 'Delete', |
| 62 | + color: Colors.red, |
| 63 | + icon: Icons.delete, |
| 64 | + //onTap: () => removeLocation(location), |
| 65 | + ), |
| 66 | + ], |
| 67 | + child: ListTile( |
| 68 | + // onTap: () { |
| 69 | + // Navigator.pushNamed(context, Routes.closeUp); |
| 70 | + // }, |
| 71 | + |
| 72 | + leading: SizedBox( |
| 73 | + width: 64.0, |
| 74 | + height: 64.0, |
| 75 | + child: ClipRRect( |
| 76 | + borderRadius: BorderRadius.circular(64.0), |
| 77 | + child: RepaintBoundary( |
| 78 | + child: Image( |
| 79 | + image: NetworkImage(snapshot.data.url), |
| 80 | + ), |
| 81 | + ), |
| 82 | + ), |
| 83 | + ), |
| 84 | + ), |
| 85 | + ); |
| 86 | + } |
| 87 | + return CircularProgressIndicator(); |
| 88 | + }, |
| 89 | + ); |
| 90 | + }, |
| 91 | + ), |
| 92 | + ); // This trailing comma makes auto-formatting nicer for build methods. |
| 93 | + } |
| 94 | +} |
0 commit comments