me_header.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 ? CachedNetworkImageProvider(user!.avatarUrl) : AssetImage('img/placeholder_avatar.png')) as ImageProvider<Object>?,
  24. ),
  25. SizedBox(width: 25),
  26. Expanded(
  27. child: Column(
  28. crossAxisAlignment: CrossAxisAlignment.start,
  29. children: <Widget>[
  30. Text(
  31. user != null ? user.nickname : '登录',
  32. style: TextStyle(fontSize: 18),
  33. ),
  34. SizedBox(height: 10),
  35. buildItems(),
  36. ],
  37. ),
  38. )
  39. ],
  40. ),
  41. ),
  42. );
  43. }
  44. Widget buildItems() {
  45. var user = UserManager.currentUser;
  46. return Row(
  47. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  48. children: <Widget>[
  49. buildItem(user != null ? user.wealth.toStringAsFixed(1) : '0.0', '书豆余额'),
  50. buildItem(user != null ? user.coupon.toString() : '0', '书券(张)'),
  51. buildItem(user != null ? user.monthlyTicket.toString() : '0', '月票'),
  52. Container(),
  53. ],
  54. );
  55. }
  56. Widget buildItem(String title, String subtitle) {
  57. return Column(
  58. crossAxisAlignment: CrossAxisAlignment.start,
  59. children: <Widget>[
  60. Text(
  61. title,
  62. style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
  63. ),
  64. SizedBox(height: 5),
  65. Text(
  66. subtitle,
  67. style: TextStyle(fontSize: 12, color: SQColor.gray),
  68. ),
  69. ],
  70. );
  71. }
  72. }