Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. class FloatingActionButtonWidget extends StatefulWidget {
  2. @override
  3. _FloatingActionButtonWidgetState createState() =>
  4. _FloatingActionButtonWidgetState();
  5. }
  6.  
  7. class _FloatingActionButtonWidgetState
  8. extends State<FloatingActionButtonWidget> {
  9. bool _isMini = false;
  10. FloatingActionButtonLocation _fabLocation =
  11. FloatingActionButtonLocation.centerDocked;
  12.  
  13. static final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  14.  
  15. @override
  16. Widget build(BuildContext context) {
  17. return Scaffold(
  18. key: _scaffoldKey,
  19. appBar: AppBar(
  20. centerTitle: true,
  21. title:Text(
  22. 'FAB Widget',
  23. style: TextStyle(
  24. fontSize: 20.0,
  25. fontWeight: FontWeight.bold,
  26. fontFamily: Utils.ubuntuRegularFont),
  27. ),
  28. actions: <Widget>[
  29. IconButton(
  30. icon: Icon(Icons.code),
  31. onPressed: () => Navigator.push(
  32. context,
  33. MaterialPageRoute(
  34. builder: (context) => CodeScreen(code: Code.fabCode),
  35. ),
  36. ),
  37. )
  38. ],
  39. ),
  40. body: ListView(
  41. padding: const EdgeInsets.only(bottom: 88.0),
  42. children: <Widget>[
  43. Center(
  44. child: Container(
  45. margin: EdgeInsets.only(top: 24),
  46. child: Text(
  47. 'Select Fab Size',
  48. style: TextStyle(
  49. color: Colors.black87,
  50. fontSize: 18.0,
  51. fontWeight: FontWeight.bold,
  52. fontFamily: Utils.ubuntuRegularFont),
  53. ),
  54. ),
  55. ),
  56. Container(
  57. margin: EdgeInsets.all(18),
  58. child: Row(
  59. mainAxisAlignment: MainAxisAlignment.start,
  60. children: <Widget>[
  61. _OptionItem(false, _isMini, _onSizeChange, 'Normal'),
  62.  
  63. _OptionItem(true, _isMini, _onSizeChange, 'Mini'),
  64. ],
  65. ),
  66. ),
  67.  
  68. divider(context),
  69.  
  70. Center(
  71. child: Container(
  72. margin: EdgeInsets.only(top: 24),
  73. child: Text(
  74. 'Select Fab Position',
  75. style: TextStyle(
  76. color: Colors.black87,
  77. fontSize: 18.0,
  78. fontWeight: FontWeight.bold,
  79. fontFamily: Utils.ubuntuRegularFont),
  80. ),
  81. ),
  82. ),
  83.  
  84. ///Container containing all the Radio buttons
  85. Container(
  86. margin: EdgeInsets.all(18),
  87. child: Wrap(
  88. children: <Widget>[
  89. _OptionItem(FloatingActionButtonLocation.centerDocked, _fabLocation, _onLocationChanged, 'Center (Docked)'),
  90.  
  91. _OptionItem(FloatingActionButtonLocation.endDocked, _fabLocation, _onLocationChanged, 'End (Docked)'),
  92.  
  93. _OptionItem(FloatingActionButtonLocation.centerFloat, _fabLocation, _onLocationChanged, 'Center (Float)'),
  94.  
  95. _OptionItem(FloatingActionButtonLocation.endFloat, _fabLocation, _onLocationChanged, 'End (Float)'),
  96. ],
  97. ),
  98. )
  99. ],
  100. ),
  101. floatingActionButton: FloatingActionButton(
  102. onPressed: () => _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("You clicked on the FAB"))),
  103. child: Icon(Icons.add),
  104. foregroundColor: Colors.white,
  105. backgroundColor: Colors.orange,
  106. elevation: 2.0,
  107. mini: _isMini,
  108. ),
  109. bottomNavigationBar: BottomAppBar(
  110. color: Colors.blueAccent,
  111. shape: CircularNotchedRectangle(),
  112. notchMargin: 4,
  113. child: Container(
  114. height: 50.0,
  115. ),
  116. ),
  117. floatingActionButtonLocation: _fabLocation,
  118. );
  119. }
  120.  
  121. ///method called whenever a radio button is clicked on to change position
  122. _onLocationChanged(FloatingActionButtonLocation value) => setState(() {
  123. _fabLocation = value;
  124. });
  125.  
  126. ///method called whenever you want to change size
  127. _onSizeChange(bool value) => setState(() {
  128. _isMini = value;
  129. });
  130.  
  131. }
  132.  
  133. /// Class to create an option for the user to select for any <T> type.
  134. /// Value -> The value that the radio button will set when it is clicked
  135. /// Group value -> A value common to a group of radio buttons that is related to the
  136. /// kind of values that each group member can set eg a boolean value or a
  137. /// FloatingActionButtonLocation value etc.
  138. /// onChanged -> the method that is to be called when clicked on a radio button
  139. ///
  140. /// When the Group value and Value of a Radio button is same, that radio button
  141. /// is marked as Selected
  142. class _OptionItem<T> extends StatelessWidget {
  143. const _OptionItem(this.value, this.groupValue, this.onChanged, this.title);
  144.  
  145. final String title;
  146. final T value;
  147. final T groupValue;
  148. final ValueChanged<T> onChanged;
  149.  
  150. @override
  151. Widget build(BuildContext context) {
  152. return Row(
  153. mainAxisSize: MainAxisSize.min,
  154. mainAxisAlignment: MainAxisAlignment.center,
  155. children: <Widget>[
  156. Radio<T>(
  157. value: value,
  158. groupValue: groupValue,
  159. activeColor: Colors.lightBlue,
  160. onChanged: onChanged
  161. ),
  162. GestureDetector(
  163. onTap: () {
  164. onChanged(value);
  165. },
  166. child: Text(
  167. title,
  168. style: TextStyle(
  169. fontSize: 14.0, fontFamily: Utils.ubuntuRegularFont),
  170. ),
  171. ),
  172. ],
  173. );
  174. }
  175. }
  176.  
  177. Container divider(BuildContext context) => Container(
  178. child: Divider(),
  179. margin: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
  180. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement