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
86026f1
commit 7a9a39c
Showing
8 changed files
with
230 additions
and
6 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
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,143 @@ | ||
import 'package:commons/src/functions/navigation_functions.dart'; | ||
import 'package:commons/src/models/models.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class __RadioListDialog extends StatefulWidget { | ||
final String title; | ||
final Set<SimpleItem> dataSet; | ||
final Data selectedItem; | ||
final Function(SimpleItem) onSubmit; | ||
|
||
__RadioListDialog( | ||
this.title, | ||
this.dataSet, | ||
this.onSubmit, { | ||
this.selectedItem, | ||
}); | ||
|
||
@override | ||
___RadioListDialogState createState() => ___RadioListDialogState(); | ||
} | ||
|
||
class ___RadioListDialogState extends State<__RadioListDialog> { | ||
SimpleItem _selectedItem; | ||
int _radioGroupId = 0; | ||
|
||
_optionItem(BuildContext context, SimpleItem data) { | ||
return RadioListTile( | ||
groupValue: _radioGroupId, | ||
onChanged: (value) { | ||
print(value); | ||
setState(() { | ||
_radioGroupId = value; | ||
_selectedItem = data; | ||
}); | ||
}, | ||
value: data.id, | ||
title: Text("${data.title}"), | ||
); | ||
} | ||
|
||
_options() { | ||
var listItems = List<Widget>(); | ||
widget.dataSet.forEach((item) { | ||
listItems.add(_optionItem(context, item)); | ||
}); | ||
return listItems; | ||
} | ||
|
||
_dialogContent(BuildContext context) { | ||
return 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, | ||
), | ||
Flexible( | ||
fit: FlexFit.loose, | ||
child: SingleChildScrollView( | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: <Widget>[ | ||
..._options(), | ||
], | ||
), | ||
), | ||
), | ||
Divider( | ||
color: Colors.black, | ||
height: 5, | ||
), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: <Widget>[ | ||
FlatButton( | ||
onPressed: () { | ||
if (widget.onSubmit != null) widget.onSubmit(_selectedItem); | ||
pop(context); // To close the dialog | ||
}, | ||
child: Text("Done"), | ||
), | ||
], | ||
) | ||
], | ||
); | ||
} | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
setState(() { | ||
if (widget.selectedItem != null) { | ||
_selectedItem = widget.selectedItem; | ||
_radioGroupId = widget.selectedItem.id; | ||
} | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Dialog( | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(8.0), | ||
), | ||
child: _dialogContent(context), | ||
elevation: 3, | ||
); | ||
} | ||
} | ||
|
||
radioListDialog( | ||
BuildContext context, | ||
String title, | ||
Set<SimpleItem> dataSet, | ||
Function(SimpleItem) onSubmit, { | ||
Data selectedItem, | ||
autoClose = true, | ||
}) { | ||
return showDialog( | ||
barrierDismissible: autoClose, | ||
context: context, | ||
builder: (c) => WillPopScope( | ||
onWillPop: () async => autoClose, | ||
child: __RadioListDialog( | ||
title, | ||
dataSet, | ||
onSubmit, | ||
selectedItem: selectedItem, | ||
), | ||
), | ||
); | ||
} |
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