error.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. static const String ASSETS_NO_NETWORK = "emptypage-image-nonetwork.png";
  10. static const String ASSETS_NO_COMMENT = "emptypage-image-nocomment.png";
  11. static const String ASSETS_NO_INVITATION = "emptypage-image-noinvitation.png";
  12. static const String ASSETS_NO_MOTION = "emptypage-image-nomotion.png";
  13. static const String ASSETS_NO_RANK = "emptypage-image-noattainment.png";
  14. RequestErrorWidget(this.callback, {this.msg = "网络出错啦,请点击按钮重新加载", this.assets = ASSETS_NO_NETWORK, this.action = "重新加载", this.marginBottom = true});
  15. @override
  16. Widget build(BuildContext context) {
  17. return Column(
  18. mainAxisSize: MainAxisSize.min,
  19. children: <Widget>[
  20. Padding(
  21. padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
  22. child: Image.asset("lib/assets/img/${this.assets}"),
  23. ),
  24. Padding(
  25. padding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
  26. child: Text(
  27. this.msg,
  28. style: Theme.of(context).textTheme.bodyText2,
  29. ),
  30. ),
  31. if (callback != null)
  32. Padding(
  33. padding: const EdgeInsets.all(16.0),
  34. child: OutlineButton(
  35. child: Text(
  36. "$action",
  37. style: TextStyle(fontSize: 14.0),
  38. ),
  39. clipBehavior: Clip.hardEdge,
  40. shape: StadiumBorder(),
  41. textColor: Color(0xff666666),
  42. color: Color(0xff666666),
  43. highlightedBorderColor: Theme.of(context).accentColor,
  44. highlightColor: Theme.of(context).accentColor,
  45. onPressed: callback,
  46. ),
  47. ),
  48. if (this.marginBottom == true)
  49. SizedBox(
  50. height: 50,
  51. )
  52. ],
  53. );
  54. }
  55. }