Created
May 19, 2021 17:26
-
-
Save afzalali15/714bac359386890f80d4420be6cdae4b to your computer and use it in GitHub Desktop.
Edit Mode Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Test Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
MyHomePage({Key? key, required this.title}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
bool _isEditMode = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
actions: [ | |
IconButton( | |
icon: Icon(Icons.edit), | |
onPressed: () { | |
setState(() { | |
_isEditMode = !_isEditMode; | |
}); | |
}, | |
), | |
], | |
), | |
body: ListView.builder( | |
itemCount: 10, | |
itemBuilder: (context, index) { | |
return ListTile( | |
leading: _isEditMode | |
? IconButton( | |
onPressed: () { | |
print('deleting -> position $index item'); | |
}, | |
icon: Icon(Icons.remove_circle, color: Colors.red), | |
) | |
: null, | |
title: Text('Item $index'), | |
); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment