setting_page.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_osc/model/constants.dart';
  3. import 'package:flutter_osc/events/LogoutEvent.dart';
  4. import '../util/DataUtils.dart';
  5. class SettingPage extends StatelessWidget {
  6. static const String TAG_START = "startDivider";
  7. static const String TAG_END = "endDivider";
  8. static const String TAG_CENTER = "centerDivider";
  9. static const String TAG_BLANK = "blankDivider";
  10. static const double IMAGE_ICON_WIDTH = 30.0;
  11. static const double ARROW_ICON_WIDTH = 16.0;
  12. final titleTextStyle = TextStyle(fontSize: 16.0);
  13. final rightArrowIcon = Image.asset(
  14. 'images/ic_arrow_right.png',
  15. width: ARROW_ICON_WIDTH,
  16. height: ARROW_ICON_WIDTH,
  17. );
  18. List listData = [];
  19. SettingPage() {
  20. listData.add(TAG_BLANK);
  21. listData.add(TAG_START);
  22. listData
  23. .add(ListItem(title: '退出登录', icon: 'images/ic_discover_nearby.png'));
  24. listData.add(TAG_END);
  25. }
  26. Widget getIconImage(path) {
  27. return Padding(
  28. padding: const EdgeInsets.fromLTRB(0.0, 0.0, 10.0, 0.0),
  29. child:
  30. Image.asset(path, width: IMAGE_ICON_WIDTH, height: IMAGE_ICON_WIDTH),
  31. );
  32. }
  33. _renderRow(BuildContext ctx, int i) {
  34. var item = listData[i];
  35. if (item is String) {
  36. Widget w = Divider(
  37. height: 1.0,
  38. );
  39. switch (item) {
  40. case TAG_START:
  41. w = Divider(
  42. height: 1.0,
  43. );
  44. break;
  45. case TAG_END:
  46. w = Divider(
  47. height: 1.0,
  48. );
  49. break;
  50. case TAG_CENTER:
  51. w = Padding(
  52. padding: const EdgeInsets.fromLTRB(50.0, 0.0, 0.0, 0.0),
  53. child: Divider(
  54. height: 1.0,
  55. ),
  56. );
  57. break;
  58. case TAG_BLANK:
  59. w = Container(
  60. height: 20.0,
  61. );
  62. break;
  63. }
  64. return w;
  65. } else if (item is ListItem) {
  66. var listItemContent = Padding(
  67. padding: const EdgeInsets.fromLTRB(10.0, 15.0, 10.0, 15.0),
  68. child: Row(
  69. children: [
  70. getIconImage(item.icon),
  71. Expanded(
  72. child: Text(
  73. item.title!,
  74. style: titleTextStyle,
  75. )),
  76. rightArrowIcon
  77. ],
  78. ),
  79. );
  80. return InkWell(
  81. onTap: () {
  82. String? title = item.title;
  83. if (title == '退出登录') {
  84. DataUtils.clearLoginInfo().then((arg) {
  85. Navigator.of(ctx).pop();
  86. Constants.eventBus.fire(LogoutEvent());
  87. print("event fired!");
  88. });
  89. }
  90. },
  91. child: listItemContent,
  92. );
  93. }
  94. }
  95. @override
  96. Widget build(BuildContext context) {
  97. return Scaffold(
  98. appBar: AppBar(
  99. title: Text("设置", style: TextStyle(color: Colors.white)),
  100. iconTheme: IconThemeData(color: Colors.white),
  101. ),
  102. body: ListView.builder(
  103. itemBuilder: (ctx, i) => _renderRow(ctx, i),
  104. itemCount: listData.length,
  105. ),
  106. );
  107. }
  108. }
  109. class ListItem {
  110. String? icon;
  111. String? title;
  112. ListItem({this.icon, this.title});
  113. }