user_widget.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'dart:math';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:sport/bean/achievement_info.dart';
  5. const LEVEL_BG_COLOR = [Color(0xffFFEDDF), Color(0xffFFEDDF), Color(0xffFFEDDF), Color(0xffFFEDDF), Color(0xffEBF0FB), Color(0xffEBF0FB), Color(0xffEBF0FB), Color(0xffFFEFD4),Color(0xffFFEFD4), Color(0xffFFEFD4), Color(0xffFFEFD4)];
  6. const LEVEL_TEXT_COLOR = [Color(0xffCB6C39), Color(0xffCB6C39), Color(0xffCB6C39), Color(0xffCB6C39), Color(0xff767FB5), Color(0xff767FB5), Color(0xff767FB5), Color(0xffFF5B1D), Color(0xffFF5B1D), Color(0xffFF5B1D), Color(0xffFF5B1D)];
  7. class UserLevelWidget extends StatelessWidget {
  8. final Level? level;
  9. @override
  10. Widget build(BuildContext context) {
  11. if (level == null) return Container();
  12. int index = min(LEVEL_BG_COLOR.length - 1, max(1, level?.level ?? 0));
  13. return Container(
  14. margin: const EdgeInsets.fromLTRB(6.0, 0, 2, 4),
  15. child: Stack(
  16. alignment: Alignment.centerLeft,
  17. children: [
  18. Container(
  19. margin: const EdgeInsets.fromLTRB(12.0, 6, 6, 2),
  20. padding: const EdgeInsets.only(right: 6, bottom: 3.0, top: 2.0, left: 14.0),
  21. decoration: BoxDecoration(borderRadius: BorderRadius.circular(100), color: LEVEL_BG_COLOR[index]),
  22. child: Align(
  23. alignment: Alignment.centerRight,
  24. child: Text(
  25. "Lv.${min(level?.level ?? 0, 99)}",
  26. style: Theme.of(context).textTheme.subtitle1!.copyWith(color: LEVEL_TEXT_COLOR[index], fontSize: 9.0),
  27. ),
  28. ),
  29. ),
  30. CachedNetworkImage(
  31. imageUrl: level?.logo ?? "",
  32. width: 22.0,
  33. height: 22.0,
  34. ),
  35. ],
  36. ),
  37. );
  38. }
  39. UserLevelWidget({
  40. this.level,
  41. });
  42. }