alert_dialog.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'dart:async';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:sport/bean/user_friend.dart';
  6. import 'package:sport/bean/user_info.dart';
  7. import 'package:sport/services/api/inject_api.dart';
  8. import 'package:sport/utils/toast.dart';
  9. import 'package:sport/widgets/button_cancel.dart';
  10. import 'package:sport/widgets/button_primary.dart';
  11. import 'package:sport/widgets/misc.dart';
  12. import '../space.dart';
  13. class CustomAlertDialog extends StatelessWidget {
  14. final String title;
  15. final Widget child;
  16. final String textCancel;
  17. final String textOk;
  18. final Function ok;
  19. final bool addClose;
  20. final bool isLine;
  21. CustomAlertDialog({
  22. this.title,
  23. this.child,
  24. this.textCancel = "取消",
  25. this.textOk = "确定",
  26. this.ok,
  27. this.addClose = false,
  28. this.isLine = false,
  29. });
  30. @override
  31. Widget build(BuildContext context) {
  32. var _width =
  33. MediaQuery.of(context).size.width * (child != null ? 0.86 : 0.66);
  34. return Material(
  35. type: MaterialType.transparency,
  36. child: Scaffold(
  37. backgroundColor: Colors.transparent,
  38. body: Center(
  39. child: Container(
  40. width: _width,
  41. decoration: BoxDecoration(
  42. borderRadius: BorderRadius.all(Radius.circular(10.0)),
  43. color: Colors.white,
  44. ),
  45. child: Column(
  46. mainAxisSize: MainAxisSize.min,
  47. children: <Widget>[
  48. if (addClose)
  49. Align(
  50. alignment: Alignment.topRight,
  51. child: IconButton(
  52. icon: Image.asset("lib/assets/img/btn_close_big.png"),
  53. onPressed: () => Navigator.pop(context, false),
  54. )),
  55. if (title != null)
  56. Stack(
  57. children: <Widget>[
  58. Padding(
  59. padding: EdgeInsets.fromLTRB(
  60. 0,
  61. child != null ? addClose ? 0 : 16.0 : 32.0,
  62. 0,
  63. isLine ? 15.0 : 20),
  64. child: Column(
  65. children: <Widget>[
  66. isLine
  67. ? Padding(
  68. child: Text(
  69. title,
  70. style: Theme.of(context)
  71. .textTheme
  72. .headline3,
  73. strutStyle: fixedLine,
  74. ),
  75. padding: EdgeInsets.only(
  76. top: 5.0, bottom: 8.0),
  77. )
  78. : Text(
  79. title,
  80. style:
  81. Theme.of(context).textTheme.headline3,
  82. strutStyle: fixedLine,
  83. ),
  84. if (isLine)
  85. Divider(
  86. endIndent: 20.0,
  87. indent: 20.0,
  88. )
  89. ],
  90. ))
  91. ],
  92. ),
  93. //
  94. if (child != null)
  95. ConstrainedBox(
  96. constraints: BoxConstraints(
  97. maxHeight: MediaQuery.of(context).size.height - 100),
  98. child: SingleChildScrollView(
  99. child: child,
  100. )),
  101. Padding(
  102. padding: const EdgeInsets.fromLTRB(16.0, 20.0, 16.0, 16.0),
  103. child: Row(
  104. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  105. children: <Widget>[
  106. Expanded(
  107. child: CancelButton(
  108. height: 35,
  109. callback: () {
  110. Navigator.of(context).pop(false);
  111. },
  112. content: textCancel),
  113. ),
  114. SizedBox(
  115. width: 16,
  116. ),
  117. Expanded(
  118. child: PrimaryButton(
  119. height: 35, callback: ok, content: textOk))
  120. ],
  121. ),
  122. )
  123. ],
  124. ),
  125. ),
  126. ),
  127. ),
  128. );
  129. }
  130. }