base_dialog.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/resources.dart';
  3. import 'package:liftmanager/routers/fluro_navigator.dart';
  4. import 'package:liftmanager/utils/theme_utils.dart';
  5. /// 自定义dialog的模板
  6. class BaseDialog extends StatelessWidget{
  7. const BaseDialog({
  8. Key key,
  9. this.title,
  10. this.onPressed,
  11. this.hiddenTitle : false,
  12. @required this.child
  13. }) : super(key : key);
  14. final String title;
  15. final Function onPressed;
  16. final Widget child;
  17. final bool hiddenTitle;
  18. @override
  19. Widget build(BuildContext context) {
  20. return Scaffold(//创建透明层
  21. resizeToAvoidBottomInset: false,
  22. backgroundColor: Colors.transparent,
  23. // 键盘弹出收起动画过渡
  24. body: AnimatedContainer(
  25. alignment: Alignment.center,
  26. height: MediaQuery.of(context).size.height - MediaQuery.of(context).viewInsets.bottom,
  27. duration: const Duration(milliseconds: 120),
  28. curve: Curves.easeInCubic,
  29. child: Container(
  30. decoration: BoxDecoration(
  31. color: ThemeUtils.getDialogBackgroundColor(context),
  32. borderRadius: BorderRadius.circular(8.0),
  33. ),
  34. width: 270.0,
  35. padding: const EdgeInsets.only(top: 24.0),
  36. child: Column(
  37. mainAxisSize: MainAxisSize.min,
  38. children: <Widget>[
  39. Offstage(
  40. offstage: hiddenTitle,
  41. child: Padding(
  42. padding: const EdgeInsets.only(bottom: 8.0),
  43. child: Text(
  44. hiddenTitle ? "" : title,
  45. style: TextStyles.textBold18,
  46. ),
  47. ),
  48. ),
  49. Flexible(child: child),
  50. Gaps.vGap8,
  51. Gaps.line,
  52. Row(
  53. children: <Widget>[
  54. Expanded(
  55. child: SizedBox(
  56. height: 48.0,
  57. child: FlatButton(
  58. child: const Text(
  59. "取消",
  60. style: TextStyle(
  61. fontSize: Dimens.font_sp18
  62. ),
  63. ),
  64. textColor: Colours.text_gray,
  65. onPressed: (){
  66. NavigatorUtils.goBack(context);
  67. },
  68. ),
  69. ),
  70. ),
  71. const SizedBox(
  72. height: 48.0,
  73. width: 0.6,
  74. child: const VerticalDivider(),
  75. ),
  76. Expanded(
  77. child: SizedBox(
  78. height: 48.0,
  79. child: FlatButton(
  80. child: const Text(
  81. "确定",
  82. style: TextStyle(
  83. fontSize: Dimens.font_sp18
  84. ),
  85. ),
  86. textColor: Theme.of(context).primaryColor,
  87. onPressed: (){
  88. onPressed();
  89. },
  90. ),
  91. ),
  92. )
  93. ],
  94. )
  95. ],
  96. )
  97. ),
  98. ),
  99. );
  100. }
  101. }