forked from ArbazMateen/commons-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b900e82
commit dfa0195
Showing
9 changed files
with
210 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## [0.5.0] - Options Dialog | ||
|
||
* Options dialog added | ||
|
||
## [0.4.9] - Readme.md file update | ||
|
||
* Readme.md file update | ||
|
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import 'package:commons/commons.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class Option { | ||
final Text title; | ||
final Icon icon; | ||
final Function action; | ||
|
||
Option( | ||
this.title, | ||
this.icon, | ||
this.action, | ||
); | ||
|
||
static item(Text title, {Icon icon, Function action}) { | ||
return Option(title, icon, action); | ||
} | ||
|
||
static edit({Text title, Icon icon, Function action}) { | ||
return Option(title ?? Text("Edit"), icon ?? Icon(Icons.edit), action); | ||
} | ||
|
||
static view({Text title, Icon icon, Function action}) { | ||
return Option( | ||
title ?? Text("View"), icon ?? Icon(Icons.visibility), action); | ||
} | ||
|
||
static details({Text title, Icon icon, Function action}) { | ||
return Option(title ?? Text("Details"), icon ?? Icon(Icons.menu), action); | ||
} | ||
|
||
static delete({Text title, Icon icon, Function action}) { | ||
return Option( | ||
title ?? | ||
Text( | ||
"Delete", | ||
style: TextStyle(color: Colors.red), | ||
), | ||
icon ?? | ||
Icon( | ||
Icons.delete, | ||
color: Colors.red, | ||
), | ||
action); | ||
} | ||
} | ||
|
||
class OptionsDialog extends StatefulWidget { | ||
final String title; | ||
final List<Option> options; | ||
|
||
OptionsDialog({this.title, this.options}); | ||
|
||
@override | ||
_OptionsDialogState createState() => _OptionsDialogState(); | ||
} | ||
|
||
class _OptionsDialogState extends State<OptionsDialog> { | ||
_optionItem(BuildContext context, Option option) { | ||
return ListTile( | ||
onTap: () { | ||
pop(context); | ||
if (option.action != null) option.action(); | ||
}, | ||
leading: option.icon, | ||
title: option.title, | ||
); | ||
} | ||
|
||
_options() { | ||
var listItems = List<Widget>(); | ||
widget.options.forEach((item) { | ||
listItems.add(_optionItem(context, item)); | ||
}); | ||
return listItems; | ||
} | ||
|
||
_dialogContent(BuildContext context) { | ||
return SingleChildScrollView( | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: Text( | ||
widget.title, | ||
textAlign: TextAlign.center, | ||
style: TextStyle( | ||
fontWeight: FontWeight.bold, | ||
fontSize: 20, | ||
), | ||
), | ||
), | ||
Divider( | ||
color: Colors.black, | ||
height: 5, | ||
), | ||
..._options(), | ||
], | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Dialog( | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(8.0), | ||
), | ||
child: _dialogContent(context), | ||
elevation: 3, | ||
); | ||
} | ||
} | ||
|
||
optionsDialog( | ||
BuildContext context, | ||
String title, | ||
List<Option> options, { | ||
autoClose = true, | ||
}) { | ||
return showDialog( | ||
barrierDismissible: autoClose, | ||
context: context, | ||
builder: (c) => WillPopScope( | ||
onWillPop: () async => autoClose, | ||
child: OptionsDialog( | ||
title: title, | ||
options: options, | ||
), | ||
), | ||
); | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.