alert_dialog.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. CustomAlertDialog({
  21. this.title,
  22. this.child,
  23. this.textCancel = "取消",
  24. this.textOk = "确定",
  25. this.ok,
  26. this.addClose = false,
  27. });
  28. @override
  29. Widget build(BuildContext context) {
  30. var _width =
  31. MediaQuery.of(context).size.width * (child != null ? 0.86 : 0.66);
  32. return Material(
  33. type: MaterialType.transparency,
  34. child: Center(
  35. child: Container(
  36. width: _width,
  37. decoration: BoxDecoration(
  38. borderRadius: BorderRadius.all(Radius.circular(10.0)),
  39. color: Colors.white,
  40. ),
  41. child: Column(
  42. mainAxisSize: MainAxisSize.min,
  43. children: <Widget>[
  44. if (addClose)
  45. Align(
  46. alignment: Alignment.topRight,
  47. child: IconButton(
  48. icon: Image.asset("lib/assets/img/btn_close_big.png"),
  49. onPressed: () => Navigator.pop(context, false),
  50. )),
  51. if (title != null)
  52. Stack(
  53. children: <Widget>[
  54. Padding(
  55. padding: EdgeInsets.fromLTRB(
  56. 0, child != null ? addClose ? 0 : 16.0 : 32.0, 0, 20),
  57. child: Text(
  58. title,
  59. style: Theme.of(context).textTheme.headline3,
  60. strutStyle: fixedLine,
  61. ),
  62. )
  63. ],
  64. ),
  65. if (child != null)
  66. ConstrainedBox(
  67. constraints: BoxConstraints(
  68. maxHeight: MediaQuery.of(context).size.height - 100),
  69. child: SingleChildScrollView(
  70. child: child,
  71. )),
  72. Padding(
  73. padding: const EdgeInsets.all(16.0),
  74. child: Row(
  75. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  76. children: <Widget>[
  77. Expanded(
  78. child: CancelButton(
  79. height: 35,
  80. callback: () {
  81. Navigator.of(context).pop(false);
  82. },
  83. content: textCancel),
  84. ),
  85. SizedBox(
  86. width: 16,
  87. ),
  88. Expanded(
  89. child: PrimaryButton(
  90. height: 35, callback: ok, content: textOk))
  91. ],
  92. ),
  93. )
  94. ],
  95. ),
  96. ),
  97. ),
  98. );
  99. }
  100. }