search.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import 'package:flutter/material.dart';
  2. import 'package:jmrh/constant/styles.dart';
  3. class Search extends StatefulWidget {
  4. Search({Key key}) : super(key: key);
  5. @override
  6. _SearchState createState() => _SearchState();
  7. }
  8. class _SearchState extends State<Search> {
  9. TextEditingController _controller;
  10. @override
  11. void initState() {
  12. super.initState();
  13. _controller = TextEditingController();
  14. }
  15. @override
  16. void dispose() {
  17. _controller.dispose();
  18. super.dispose();
  19. }
  20. @override
  21. Widget build(BuildContext context) {
  22. return Scaffold(
  23. body: CustomScrollView(
  24. slivers: [
  25. SliverAppBar(
  26. brightness: Brightness.light,
  27. pinned: true,
  28. backgroundColor: Colors.white,
  29. iconTheme: IconTheme.of(context).copyWith(color: Colors.black),
  30. title: appbarTitle('搜索'),
  31. leading: IconButton(
  32. icon: ImageIcon(
  33. AssetImage('img/nav_icon_return.png'),
  34. size: 28,
  35. ),
  36. onPressed: () {
  37. Navigator.pop(context);
  38. },
  39. ),
  40. bottom: PreferredSize(
  41. child: Row(
  42. children: [
  43. Expanded(
  44. child: Container(
  45. height: 36,
  46. decoration: BoxDecoration(
  47. color: COLOR_INPUT_BG,
  48. borderRadius: BorderRadius.all(Radius.circular(2))),
  49. margin: EdgeInsets.only(left: 16),
  50. padding: EdgeInsets.symmetric(horizontal: 10),
  51. child: Row(
  52. children: [
  53. Image.asset('img/icon_search.png'),
  54. Expanded(
  55. child: Container(
  56. margin: EdgeInsets.only(left: 10, right: 10),
  57. child: TextField(
  58. controller: _controller,
  59. decoration: InputDecoration.collapsed(
  60. hintText: '搜索...',
  61. ),
  62. onSubmitted: (String value) async {
  63. await showDialog<void>(
  64. context: context,
  65. builder: (BuildContext context) {
  66. return AlertDialog(
  67. title: const Text('Thanks!'),
  68. content:
  69. Text('You typed "$value".'),
  70. actions: <Widget>[
  71. FlatButton(
  72. onPressed: () {
  73. Navigator.pop(context);
  74. },
  75. child: const Text('OK'),
  76. ),
  77. ],
  78. );
  79. },
  80. );
  81. },
  82. )),
  83. ),
  84. ],
  85. ),
  86. ),
  87. ),
  88. Container(
  89. width: 60,
  90. child: FlatButton(
  91. child: Text(
  92. '搜索',
  93. style: TextStyle(color: COLOR_PRIMARY, fontSize: 14),
  94. ),
  95. onPressed: () {},
  96. ),
  97. )
  98. ],
  99. ),
  100. preferredSize: Size.fromHeight(36)),
  101. )
  102. ],
  103. ),
  104. );
  105. }
  106. }