UserInfoPopMenuContext.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_habit/common/I18N.dart';
  3. import 'package:flutter_habit/common/components/PopMenus.dart';
  4. import 'package:flutter_habit/provider/UserProvider.dart';
  5. import 'package:flutter_habit/network/Repository.dart';
  6. import 'package:provider/provider.dart';
  7. class UserInfoPopMenuContext extends StatefulWidget {
  8. final int? uid;
  9. UserInfoPopMenuContext(this.uid);
  10. @override
  11. _UserInfoPopMenuContextState createState() => _UserInfoPopMenuContextState();
  12. }
  13. class _UserInfoPopMenuContextState extends State<UserInfoPopMenuContext> {
  14. List<int>? photo;
  15. Map? userInfo;
  16. int? coins;
  17. bool? isFollowed;
  18. @override
  19. void initState() {
  20. super.initState();
  21. photo = null;
  22. userInfo = {};
  23. coins = -1;
  24. isFollowed = false;
  25. getData();
  26. }
  27. Future<void> getData() async {
  28. UserProvider userProvider =
  29. Provider.of<UserProvider>(context, listen: false);
  30. isFollowed = await Repository.getInstance()!.getFollowState(
  31. context, userProvider.token, userProvider.uid, widget.uid);
  32. setState(() {});
  33. userInfo = await Repository.getInstance()!.getUserInfo(widget.uid);
  34. setState(() {});
  35. coins = await Repository.getInstance()!.getCoin(widget.uid);
  36. setState(() {});
  37. photo = await Repository.getInstance()!.getPhoto(widget.uid);
  38. setState(() {});
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. double size = 80;
  43. return Column(
  44. children: <Widget>[
  45. Divider(),
  46. Row(
  47. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  48. crossAxisAlignment: CrossAxisAlignment.center,
  49. children: <Widget>[
  50. photo == null || photo!.isEmpty
  51. ? Icon(
  52. Icons.account_circle,
  53. size: size,
  54. color: Theme.of(context).unselectedWidgetColor,
  55. )
  56. : ClipOval(
  57. child: Image.memory(
  58. photo as Uint8List,
  59. width: size,
  60. height: size,
  61. ),
  62. ),
  63. Column(
  64. crossAxisAlignment: CrossAxisAlignment.start,
  65. children: <Widget>[
  66. Text("${I18N.of("用户名")}: ", style: TextStyle(height: 1.5)),
  67. Text("${I18N.of("生日")}: ", style: TextStyle(height: 1.5)),
  68. Text("${I18N.of("性别")}: ", style: TextStyle(height: 1.5)),
  69. Text("${I18N.of("金币")}: ", style: TextStyle(height: 1.5)),
  70. ],
  71. ),
  72. Column(
  73. crossAxisAlignment: CrossAxisAlignment.end,
  74. children: <Widget>[
  75. userInfo == null
  76. ? Text(I18N.of("用户名"))
  77. : Text(userInfo!["userName"].toString(),
  78. style: TextStyle(height: 1.5)),
  79. userInfo == null
  80. ? Text(I18N.of("生日"))
  81. : Text(userInfo!["birthday"].toString(),
  82. style: TextStyle(height: 1.5)),
  83. userInfo == null
  84. ? Text(I18N.of("性别"))
  85. : Text(I18N.of(userInfo!["gender"].toString()),
  86. style: TextStyle(height: 1.5)),
  87. Text(coins.toString(), style: TextStyle(height: 1.5)),
  88. ],
  89. ),
  90. ],
  91. ),
  92. Divider(),
  93. Row(
  94. mainAxisAlignment: MainAxisAlignment.end,
  95. children: <Widget>[
  96. ElevatedButton(
  97. style: ButtonStyle(
  98. backgroundColor: MaterialStateProperty.all(isFollowed!
  99. ? Theme.of(context).unselectedWidgetColor
  100. : Theme.of(context).colorScheme.secondary),
  101. foregroundColor:
  102. MaterialStateProperty.all(Theme.of(context).cardColor),
  103. shape: MaterialStateProperty.all(RoundedRectangleBorder(
  104. borderRadius: BorderRadius.circular(5.0),
  105. ))),
  106. child: isFollowed! ? Text(I18N.of("取消关注")) : Text(I18N.of("关注")),
  107. onPressed: () async {
  108. UserProvider userProvider =
  109. Provider.of<UserProvider>(context, listen: false);
  110. String? res = await Repository.getInstance()!.follow(
  111. context, userProvider.token, userProvider.uid, widget.uid);
  112. if (res != null) {
  113. isFollowed = !isFollowed!;
  114. setState(() {});
  115. await PopMenus.attention(
  116. context: context,
  117. content: Text(res == "followed"
  118. ? I18N.of("关注成功")
  119. : I18N.of("取消关注成功")));
  120. Navigator.of(context).pop(res);
  121. }
  122. },
  123. ),
  124. // ElevatedButton(
  125. // color: Theme.of(context).colorScheme.secondary,
  126. // textColor: Theme.of(context).cardColor,
  127. // child: Text(I18N.of("私信")),
  128. // onPressed: () {},
  129. // ),
  130. ],
  131. ),
  132. ],
  133. );
  134. }
  135. }