alert_dialog.dart 3.5 KB

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