MyDrawer.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import 'package:flutter/material.dart';
  2. import '../pages/AboutPage.dart';
  3. import '../pages/BlackHousePage.dart';
  4. import '../pages/PublishTweetPage.dart';
  5. import '../pages/SettingsPage.dart';
  6. class MyDrawer extends StatelessWidget {
  7. static const double IMAGE_ICON_WIDTH = 30.0;
  8. static const double ARROW_ICON_WIDTH = 16.0;
  9. var rightArrowIcon = Image.asset('images/ic_arrow_right.png', width: ARROW_ICON_WIDTH, height: ARROW_ICON_WIDTH,);
  10. List menuTitles = ['发布动弹', '动弹小黑屋', '关于', '设置'];
  11. List menuIcons = ['./images/leftmenu/ic_fabu.png', './images/leftmenu/ic_xiaoheiwu.png', './images/leftmenu/ic_about.png', './images/leftmenu/ic_settings.png'];
  12. TextStyle menuStyle = TextStyle(
  13. fontSize: 15.0,
  14. );
  15. @override
  16. Widget build(BuildContext context) {
  17. return ConstrainedBox(
  18. constraints: const BoxConstraints.expand(width: 304.0),
  19. child: Material(
  20. elevation: 16.0,
  21. child: Container(
  22. decoration: BoxDecoration(
  23. color: const Color(0xFFFFFFFF),
  24. ),
  25. child: ListView.builder(
  26. itemCount: menuTitles.length * 2 + 1,
  27. itemBuilder: renderRow,
  28. ),
  29. ),
  30. ),
  31. );
  32. }
  33. Widget getIconImage(path) {
  34. return Padding(
  35. padding: const EdgeInsets.fromLTRB(2.0, 0.0, 6.0, 0.0),
  36. child: Image.asset(path, width: 28.0, height: 28.0),
  37. );
  38. }
  39. Widget renderRow(BuildContext context, int index) {
  40. if (index == 0) {
  41. // render cover image
  42. var img = Image.asset('./images/cover_img.jpg', width: 304.0, height: 304.0,);
  43. return Container(
  44. width: 304.0,
  45. height: 304.0,
  46. margin: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 10.0),
  47. child: img,
  48. );
  49. }
  50. index -= 1;
  51. if (index.isOdd) {
  52. return Divider();
  53. }
  54. index = index ~/2;
  55. var listItemContent = Padding(
  56. padding: const EdgeInsets.fromLTRB(10.0, 15.0, 10.0, 15.0),
  57. child: Row(
  58. children: [
  59. getIconImage(menuIcons[index]),
  60. Expanded(
  61. child: Text(menuTitles[index], style: menuStyle,)
  62. ),
  63. rightArrowIcon
  64. ],
  65. ),
  66. );
  67. return InkWell(
  68. child: listItemContent,
  69. onTap: () {
  70. switch (index) {
  71. case 0:
  72. // 发布动弹
  73. Navigator.of(context).push(MaterialPageRoute(
  74. builder: (ctx) {
  75. return PublishTweetPage();
  76. }
  77. ));
  78. break;
  79. case 1:
  80. // 小黑屋
  81. Navigator.of(context).push(MaterialPageRoute(
  82. builder: (ctx) {
  83. return BlackHousePage();
  84. }
  85. ));
  86. break;
  87. case 2:
  88. // 关于
  89. Navigator.of(context).push(MaterialPageRoute(
  90. builder: (ctx) {
  91. return AboutPage();
  92. }
  93. ));
  94. break;
  95. case 3:
  96. // 设置
  97. Navigator.of(context).push(MaterialPageRoute(
  98. builder: (ctx) {
  99. return SettingsPage();
  100. }
  101. ));
  102. break;
  103. }
  104. },
  105. );
  106. }
  107. }