Showing
5 changed files
with
192 additions
and
18 deletions
| 1 | import 'package:flutter/cupertino.dart'; | 1 | import 'package:flutter/cupertino.dart'; |
| 2 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_2d_amap/flutter_2d_amap.dart'; | ||
| 3 | import 'package:one_poem/poem/provider/lang_sort_provider.dart'; | 4 | import 'package:one_poem/poem/provider/lang_sort_provider.dart'; |
| 4 | import 'package:one_poem/poem/widgets/lang_sort_bottom_sheet.dart'; | 5 | import 'package:one_poem/poem/widgets/lang_sort_bottom_sheet.dart'; |
| 5 | import 'package:one_poem/res/resources.dart'; | 6 | import 'package:one_poem/res/resources.dart'; |
| ... | @@ -23,7 +24,8 @@ class PoemPublish extends StatefulWidget { | ... | @@ -23,7 +24,8 @@ class PoemPublish extends StatefulWidget { |
| 23 | class _PoemPublishState extends State<PoemPublish> { | 24 | class _PoemPublishState extends State<PoemPublish> { |
| 24 | bool isPublishing = false; | 25 | bool isPublishing = false; |
| 25 | String _langSortName = "普通话"; | 26 | String _langSortName = "普通话"; |
| 26 | - int _langSortId = 1; | 27 | + int _langSortId = 1; //TODO 传入服务器的口音ID |
| 28 | + String _address = '我在此地'; | ||
| 27 | final LangSortProvider _provider = LangSortProvider(); | 29 | final LangSortProvider _provider = LangSortProvider(); |
| 28 | 30 | ||
| 29 | @override | 31 | @override |
| ... | @@ -82,23 +84,35 @@ class _PoemPublishState extends State<PoemPublish> { | ... | @@ -82,23 +84,35 @@ class _PoemPublishState extends State<PoemPublish> { |
| 82 | ), | 84 | ), |
| 83 | ), | 85 | ), |
| 84 | ), | 86 | ), |
| 85 | - Container( | 87 | + InkWell( |
| 86 | - padding: EdgeInsets.all(10.px), | 88 | + onTap: () { |
| 87 | - alignment: Alignment.centerLeft, | 89 | + NavigatorUtils.pushResult( |
| 88 | - width: double.infinity, | 90 | + context, PoemRouter.addressSelectPage, (result) { |
| 89 | - height: 36.px, | 91 | + setState(() { |
| 90 | - child: Wrap( | 92 | + final PoiSearch model = result as PoiSearch; |
| 91 | - children: [ | 93 | + _address = |
| 92 | - Icon( | 94 | + '${model.provinceName!} ${model.cityName!} ${model.adName!} ${model.title!}'; |
| 93 | - Icons.room_outlined, | 95 | + }); |
| 94 | - size: 15.px, | 96 | + }); |
| 95 | - ), | 97 | + }, |
| 96 | - Gaps.hGap5, | 98 | + child: Container( |
| 97 | - const Text( | 99 | + padding: EdgeInsets.all(10.px), |
| 98 | - "我在此地", | 100 | + alignment: Alignment.centerLeft, |
| 99 | - style: TextStyle(color: Colors.black45), | 101 | + width: double.infinity, |
| 100 | - ), | 102 | + height: 36.px, |
| 101 | - ], | 103 | + child: Wrap( |
| 104 | + children: [ | ||
| 105 | + Icon( | ||
| 106 | + Icons.room_outlined, | ||
| 107 | + size: 15.px, | ||
| 108 | + ), | ||
| 109 | + Gaps.hGap5, | ||
| 110 | + Text( | ||
| 111 | + _address, | ||
| 112 | + style: const TextStyle(color: Colors.black45), | ||
| 113 | + ), | ||
| 114 | + ], | ||
| 115 | + ), | ||
| 102 | ), | 116 | ), |
| 103 | ), | 117 | ), |
| 104 | InkWell( | 118 | InkWell( | ... | ... |
lib/poem/page/select_address_page.dart
0 → 100644
| 1 | +import 'package:flutter/material.dart'; | ||
| 2 | +import 'package:flutter_2d_amap/flutter_2d_amap.dart'; | ||
| 3 | +import 'package:one_poem/routers/fluro_navigator.dart'; | ||
| 4 | +import 'package:one_poem/util/toast_utils.dart'; | ||
| 5 | +import 'package:one_poem/widgets/my_button.dart'; | ||
| 6 | +import 'package:one_poem/widgets/search_bar.dart'; | ||
| 7 | + | ||
| 8 | +class AddressSelectPage extends StatefulWidget { | ||
| 9 | + const AddressSelectPage({Key? key}) : super(key: key); | ||
| 10 | + | ||
| 11 | + @override | ||
| 12 | + _AddressSelectPageState createState() => _AddressSelectPageState(); | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +class _AddressSelectPageState extends State<AddressSelectPage> { | ||
| 16 | + List<PoiSearch> _list = []; | ||
| 17 | + int _index = 0; | ||
| 18 | + final ScrollController _controller = ScrollController(); | ||
| 19 | + AMap2DController? _aMap2DController; | ||
| 20 | + | ||
| 21 | + @override | ||
| 22 | + void dispose() { | ||
| 23 | + _controller.dispose(); | ||
| 24 | + super.dispose(); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + @override | ||
| 28 | + void initState() { | ||
| 29 | + super.initState(); | ||
| 30 | + // TODO 需要根据项目单独设置keys | ||
| 31 | + Flutter2dAMap.setApiKey( | ||
| 32 | + iOSKey: '4327916279bf45a044bb53b947442387', | ||
| 33 | + ); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @override | ||
| 37 | + Widget build(BuildContext context) { | ||
| 38 | + return Scaffold( | ||
| 39 | + resizeToAvoidBottomInset: false, | ||
| 40 | + appBar: SearchBar( | ||
| 41 | + hintText: '搜索地址', | ||
| 42 | + onPressed: (text) { | ||
| 43 | + _controller.animateTo(0.0, | ||
| 44 | + duration: const Duration(milliseconds: 10), curve: Curves.ease); | ||
| 45 | + _index = 0; | ||
| 46 | + _aMap2DController?.search(text); | ||
| 47 | + }, | ||
| 48 | + ), | ||
| 49 | + body: SafeArea( | ||
| 50 | + child: Column( | ||
| 51 | + children: <Widget>[ | ||
| 52 | + Expanded( | ||
| 53 | + flex: 9, | ||
| 54 | + child: AMap2DView( | ||
| 55 | + onPoiSearched: (result) { | ||
| 56 | + _controller.animateTo(0.0, | ||
| 57 | + duration: const Duration(milliseconds: 10), | ||
| 58 | + curve: Curves.ease); | ||
| 59 | + _index = 0; | ||
| 60 | + _list = result; | ||
| 61 | + setState(() {}); | ||
| 62 | + }, | ||
| 63 | + onAMap2DViewCreated: (controller) { | ||
| 64 | + _aMap2DController = controller; | ||
| 65 | + }, | ||
| 66 | + ), | ||
| 67 | + ), | ||
| 68 | + Expanded( | ||
| 69 | + flex: 11, | ||
| 70 | + child: ListView.separated( | ||
| 71 | + controller: _controller, | ||
| 72 | + itemCount: _list.length, | ||
| 73 | + separatorBuilder: (_, index) => const Divider(), | ||
| 74 | + itemBuilder: (_, index) { | ||
| 75 | + return _AddressItem( | ||
| 76 | + isSelected: _index == index, | ||
| 77 | + date: _list[index], | ||
| 78 | + onTap: () { | ||
| 79 | + _index = index; | ||
| 80 | + _aMap2DController?.move( | ||
| 81 | + _list[index].latitude!, _list[index].longitude!); | ||
| 82 | + setState(() {}); | ||
| 83 | + }, | ||
| 84 | + ); | ||
| 85 | + }, | ||
| 86 | + ), | ||
| 87 | + ), | ||
| 88 | + MyButton( | ||
| 89 | + onPressed: () { | ||
| 90 | + if (_list.isEmpty) { | ||
| 91 | + Toast.show('未选择地址!'); | ||
| 92 | + return; | ||
| 93 | + } | ||
| 94 | + NavigatorUtils.goBackWithParams(context, _list[_index]); | ||
| 95 | + }, | ||
| 96 | + text: '确认选择地址', | ||
| 97 | + ) | ||
| 98 | + ], | ||
| 99 | + ), | ||
| 100 | + ), | ||
| 101 | + ); | ||
| 102 | + } | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +class _AddressItem extends StatelessWidget { | ||
| 106 | + const _AddressItem({ | ||
| 107 | + Key? key, | ||
| 108 | + required this.date, | ||
| 109 | + this.isSelected = false, | ||
| 110 | + this.onTap, | ||
| 111 | + }) : super(key: key); | ||
| 112 | + | ||
| 113 | + final PoiSearch date; | ||
| 114 | + final bool isSelected; | ||
| 115 | + final GestureTapCallback? onTap; | ||
| 116 | + | ||
| 117 | + @override | ||
| 118 | + Widget build(BuildContext context) { | ||
| 119 | + return InkWell( | ||
| 120 | + onTap: onTap, | ||
| 121 | + child: Container( | ||
| 122 | + alignment: Alignment.centerLeft, | ||
| 123 | + padding: const EdgeInsets.symmetric(horizontal: 16.0), | ||
| 124 | + height: 50.0, | ||
| 125 | + child: Row( | ||
| 126 | + children: <Widget>[ | ||
| 127 | + Expanded( | ||
| 128 | + child: Text( | ||
| 129 | + '${date.provinceName!} ${date.cityName!} ${date.adName!} ${date.title!}', | ||
| 130 | + ), | ||
| 131 | + ), | ||
| 132 | + Visibility( | ||
| 133 | + visible: isSelected, | ||
| 134 | + child: const Icon(Icons.done, color: Colors.blue), | ||
| 135 | + ) | ||
| 136 | + ], | ||
| 137 | + ), | ||
| 138 | + ), | ||
| 139 | + ); | ||
| 140 | + } | ||
| 141 | +} |
| ... | @@ -8,6 +8,7 @@ import 'page/poem_page.dart'; | ... | @@ -8,6 +8,7 @@ import 'page/poem_page.dart'; |
| 8 | import 'page/poem_publish.dart'; | 8 | import 'page/poem_publish.dart'; |
| 9 | import 'page/poem_record_video.dart'; | 9 | import 'page/poem_record_video.dart'; |
| 10 | import 'page/poem_video_player.dart'; | 10 | import 'page/poem_video_player.dart'; |
| 11 | +import 'page/select_address_page.dart'; | ||
| 11 | 12 | ||
| 12 | class PoemRouter implements IRouterProvider { | 13 | class PoemRouter implements IRouterProvider { |
| 13 | static String poemPage = '/poem'; | 14 | static String poemPage = '/poem'; |
| ... | @@ -18,6 +19,7 @@ class PoemRouter implements IRouterProvider { | ... | @@ -18,6 +19,7 @@ class PoemRouter implements IRouterProvider { |
| 18 | static String poemPublish = '/poem/publish'; | 19 | static String poemPublish = '/poem/publish'; |
| 19 | static String poemCompletePage = '/poem/complete'; | 20 | static String poemCompletePage = '/poem/complete'; |
| 20 | static String poemSearchPage = '/poem/search'; | 21 | static String poemSearchPage = '/poem/search'; |
| 22 | + static String addressSelectPage = '/poem/address/select'; | ||
| 21 | 23 | ||
| 22 | @override | 24 | @override |
| 23 | void initRouter(FluroRouter router) { | 25 | void initRouter(FluroRouter router) { |
| ... | @@ -28,6 +30,9 @@ class PoemRouter implements IRouterProvider { | ... | @@ -28,6 +30,9 @@ class PoemRouter implements IRouterProvider { |
| 28 | ), | 30 | ), |
| 29 | ); | 31 | ); |
| 30 | 32 | ||
| 33 | + router.define(addressSelectPage, | ||
| 34 | + handler: Handler(handlerFunc: (_, __) => const AddressSelectPage())); | ||
| 35 | + | ||
| 31 | router.define( | 36 | router.define( |
| 32 | poemDetailPage, | 37 | poemDetailPage, |
| 33 | handler: Handler( | 38 | handler: Handler( | ... | ... |
| ... | @@ -356,6 +356,15 @@ packages: | ... | @@ -356,6 +356,15 @@ packages: |
| 356 | description: flutter | 356 | description: flutter |
| 357 | source: sdk | 357 | source: sdk |
| 358 | version: "0.0.0" | 358 | version: "0.0.0" |
| 359 | + flutter_2d_amap: | ||
| 360 | + dependency: "direct main" | ||
| 361 | + description: | ||
| 362 | + path: "." | ||
| 363 | + ref: "597a0538" | ||
| 364 | + resolved-ref: "597a05386700e1cf854ad9b56fe21b103c669f62" | ||
| 365 | + url: "https://github.com/simplezhli/flutter_2d_amap.git" | ||
| 366 | + source: git | ||
| 367 | + version: "0.2.0+2" | ||
| 359 | flutter_blurhash: | 368 | flutter_blurhash: |
| 360 | dependency: transitive | 369 | dependency: transitive |
| 361 | description: | 370 | description: | ... | ... |
| ... | @@ -80,6 +80,11 @@ dependencies: | ... | @@ -80,6 +80,11 @@ dependencies: |
| 80 | # The following adds the Cupertino Icons font to your application. | 80 | # The following adds the Cupertino Icons font to your application. |
| 81 | # Use with the CupertinoIcons class for iOS style icons. | 81 | # Use with the CupertinoIcons class for iOS style icons. |
| 82 | cupertino_icons: ^1.0.2 | 82 | cupertino_icons: ^1.0.2 |
| 83 | + # 高德2D地图插件(支持Web) https://github.com/simplezhli/flutter_2d_amap | ||
| 84 | + flutter_2d_amap: | ||
| 85 | + git: | ||
| 86 | + ref: '597a0538' | ||
| 87 | + url: 'https://github.com/simplezhli/flutter_2d_amap.git' | ||
| 83 | 88 | ||
| 84 | # tiktok | 89 | # tiktok |
| 85 | video_player: ^2.2.10 | 90 | video_player: ^2.2.10 | ... | ... |
-
Please register or login to post a comment