me_header.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import 'package:flutter/material.dart';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:shuqi/public.dart';
  4. class MeHeader extends StatelessWidget {
  5. @override
  6. Widget build(BuildContext context) {
  7. var user = UserManager.currentUser;
  8. return GestureDetector(
  9. onTap: () {
  10. if (UserManager.instance.isLogin) {
  11. AppNavigator.pushWeb(context, 'https://github.com/huanxsd/flutter_shuqi', 'Github');
  12. } else {
  13. AppNavigator.pushLogin(context);
  14. }
  15. },
  16. child: Container(
  17. color: SQColor.white,
  18. padding: EdgeInsets.fromLTRB(20, 30, 15, 15),
  19. child: Row(
  20. children: <Widget>[
  21. CircleAvatar(
  22. radius: 40,
  23. backgroundImage: (user?.avatarUrl != null
  24. ? CachedNetworkImageProvider(user!.avatarUrl)
  25. : AssetImage('assets/img/placeholder_avatar.png'))
  26. as ImageProvider<Object>?,
  27. ),
  28. SizedBox(width: 25),
  29. Expanded(
  30. child: Column(
  31. crossAxisAlignment: CrossAxisAlignment.start,
  32. children: <Widget>[
  33. Text(
  34. user != null ? user.nickname : '登录',
  35. style: TextStyle(fontSize: 18),
  36. ),
  37. SizedBox(height: 10),
  38. buildItems(),
  39. ],
  40. ),
  41. )
  42. ],
  43. ),
  44. ),
  45. );
  46. }
  47. Widget buildItems() {
  48. var user = UserManager.currentUser;
  49. return Row(
  50. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  51. children: <Widget>[
  52. buildItem(user != null ? user.wealth.toStringAsFixed(1) : '0.0', '书豆余额'),
  53. buildItem(user != null ? user.coupon.toString() : '0', '书券(张)'),
  54. buildItem(user != null ? user.monthlyTicket.toString() : '0', '月票'),
  55. Container(),
  56. ],
  57. );
  58. }
  59. Widget buildItem(String title, String subtitle) {
  60. return Column(
  61. crossAxisAlignment: CrossAxisAlignment.start,
  62. children: <Widget>[
  63. Text(
  64. title,
  65. style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
  66. ),
  67. SizedBox(height: 5),
  68. Text(
  69. subtitle,
  70. style: TextStyle(fontSize: 12, color: SQColor.gray),
  71. ),
  72. ],
  73. );
  74. }
  75. }