error.dart 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. class RequestErrorWidget extends StatelessWidget {
  4. final VoidCallback? callback;
  5. final String msg;
  6. final String assets;
  7. final String action;
  8. final bool marginBottom;
  9. final double padding;
  10. static const String ASSETS_NO_NETWORK = "emptypage-image-nonetwork.png";
  11. static const String ASSETS_NO_COMMENT = "emptypage-image-nocomment.png";
  12. static const String ASSETS_NO_INVITATION = "emptypage-image-noinvitation.png";
  13. static const String ASSETS_NO_MOTION = "emptypage-image-nomotion.png";
  14. static const String ASSETS_NO_RANK = "emptypage-image-noattainment.png";
  15. RequestErrorWidget(this.callback,
  16. {this.msg = "网络出错啦,请点击按钮重新加载",
  17. this.assets = ASSETS_NO_NETWORK,
  18. this.action = "重新加载",
  19. this.marginBottom = true,
  20. this.padding = 50});
  21. @override
  22. Widget build(BuildContext context) {
  23. return Column(
  24. mainAxisSize: MainAxisSize.min,
  25. children: <Widget>[
  26. Padding(
  27. padding: EdgeInsets.fromLTRB(0, this.padding, 0, 0),
  28. child: Image.asset("lib/assets/img/${this.assets}"),
  29. ),
  30. Padding(
  31. padding: const EdgeInsets.all(12.0),
  32. child: Text(
  33. this.msg,
  34. style: Theme.of(context).textTheme.bodyText2!,
  35. ),
  36. ),
  37. if (callback != null)
  38. Padding(
  39. padding: const EdgeInsets.all(16.0),
  40. child: OutlinedButton(
  41. child: Text(
  42. "$action",
  43. style: Theme.of(context).textTheme.bodyText1,
  44. ),
  45. style: ButtonStyle(shape: MaterialStateProperty.all(StadiumBorder())),
  46. clipBehavior: Clip.hardEdge,
  47. onPressed: callback,
  48. ),
  49. ),
  50. if (this.marginBottom == true)
  51. SizedBox(
  52. height: this.padding,
  53. )
  54. ],
  55. );
  56. }
  57. }