From 0daa197dbaf611eacdf9eeb3763ddcb10038585b Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 03 十一月 2021 19:20:07 +0800 Subject: [PATCH] 功能完善 --- lib/ui/main/location.dart | 848 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 634 insertions(+), 214 deletions(-) diff --git a/lib/ui/main/location.dart b/lib/ui/main/location.dart index fe54be4..e67a58f 100644 --- a/lib/ui/main/location.dart +++ b/lib/ui/main/location.dart @@ -4,12 +4,19 @@ import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; +import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; import 'package:location/ui/mine/advice.dart'; import 'package:location/ui/mine/permission.dart'; import 'package:location/ui/mine/settings.dart'; import 'package:location/ui/mine/share_to_friends.dart'; import 'package:location/ui/mine/try_functions.dart'; +import 'package:location/ui/widget/button.dart'; import 'package:location/utils/pageutils.dart'; +import 'package:location/utils/ui_constant.dart'; + +typedef OnPositionHiidenChange = void Function(bool hidden); + +BMFMapController? _mapController; class MyApp extends StatelessWidget { // This widget is the root of your application. @@ -52,13 +59,14 @@ } class _LocationPageState extends State<LocationPage> - with SingleTickerProviderStateMixin { - //浣嶇疆淇℃伅鏄惁闅愯棌 - bool locationInfoHidden = true; + with AutomaticKeepAliveClientMixin { BMFMapOptions mapOptions = BMFMapOptions( + showMapScaleBar: false, + mapType: BMFMapType.Standard, center: BMFCoordinate(39.917215, 116.380341), + mapScaleBarPosition: BMFPoint(0, 200), zoomLevel: 12, - mapPadding: BMFEdgeInsets(left: 30, top: 0, right: 30, bottom: 0)); + mapPadding: BMFEdgeInsets(left: 30, top: 0, right: 30, bottom: 200)); @override void initState() { @@ -68,179 +76,16 @@ @override Widget build(BuildContext context) { return Scaffold( + resizeToAvoidBottomInset: false, backgroundColor: Colors.white, body: Stack( children: [ getMapView(), - Container( - padding: const EdgeInsets.fromLTRB(10, 35, 10, 0), - child: Flex(direction: Axis.vertical, children: [ - //----------鎼滅储妗�-------- - Flex( - direction: Axis.horizontal, - children: [ - Expanded( - child: InkWell( - onTap: () { - print("璺宠浆瀹氫綅"); - }, - child: Container( - alignment: Alignment.center, - padding: EdgeInsets.fromLTRB(13, 0, 13, 0), - height: 45, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(10), - boxShadow: getViewShadow()), - child: Flex( - direction: Axis.horizontal, - children: [ - Image.asset( - "assets/images/main/icon_location_search.png", - height: 19, - ), - Container( - width: 10, - ), - const Expanded( - child: Text("鍦板浘涓婃壘浣嶇疆", - style: TextStyle( - fontSize: 14, - color: Color(0xFFC4CDD1)))) - ], - ), - ))), - InkWell( - onTap: () { - print("sos"); - }, - child: Container( - width: 45, - height: 45, - margin: const EdgeInsets.only(left: 8.5), - decoration: BoxDecoration( - color: Colors.white, - boxShadow: getViewShadow(), - borderRadius: BorderRadius.circular(23)), - alignment: Alignment.center, - child: Image.asset( - "assets/images/main/icon_location_sos.png", - height: 35, - ), - )) - ], - ), - //---------涓汉淇℃伅涓庡畾浣嶄俊鎭�--- - Container( - height: 400, - child: Stack( - children: [ - //浣嶇疆淇℃伅 - getPositionInfoView(), - - //涓汉淇℃伅 - Container( - height: 100, - margin: EdgeInsets.only(top: 10), - padding: - EdgeInsets.only(left: 15, top: 8, right: 15), - decoration: BoxDecoration( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular( - locationInfoHidden ? 10 : 0), - bottomRight: Radius.circular( - locationInfoHidden ? 10 : 0), - topLeft: Radius.circular(10), - topRight: Radius.circular(10)), - color: Colors.white, - boxShadow: getViewShadow()), - child: Stack( - alignment: Alignment.topCenter, - children: [ - Flex( - mainAxisAlignment: MainAxisAlignment.center, - direction: Axis.horizontal, - children: [ - Image.asset( - "assets/images/main/icon_location_change_person.png", - width: 13, - ), - Text( - " 鍒囨崲瀹炴椂瀹氫綅浜�", - style: TextStyle( - color: Color(0xFF0E95FE), - fontSize: 15), - ) - ], - ), - //涓汉淇℃伅 - Flex(direction: Axis.horizontal,children: [],) - - ], - ), - ), - - //鏇村 - Positioned( - left: MediaQuery.of(context).size.width / 2 - - 10 - - 70 / 2, - top: 80, - child: InkWell( - onTap: () { - setState(() { - locationInfoHidden = !locationInfoHidden; - }); - }, - child: Container( - width: 70, - height: 40, - child: Stack( - alignment: Alignment.bottomCenter, - children: [ - Container( - height: 30, - width: 60, - margin: EdgeInsets.only(top: 0), - alignment: Alignment.center, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: - BorderRadius.circular(15), - boxShadow: getViewShadow()), - ), - Positioned( - top: 0, - child: Container( - height: 25, - width: 70, - alignment: - Alignment.bottomCenter, - - decoration: BoxDecoration( - color: Colors.white, - ), - // child: Text( - // "鏀惰捣", - // style: TextStyle( - // color: Color(0xFF0E95FE), - // fontSize: 11), - // ) - )), - Positioned( - bottom: 5, - child: Text( - locationInfoHidden - ? "灞曞紑" - : "鏀惰捣", - style: TextStyle( - color: Color(0xFF0E95FE), - fontSize: 11), - )), - ])))) - ], - )), - ])), + // PositionInfoPage((bool hiiden) { + // + // + // }), + LocationSearchPage(), Align( alignment: Alignment.bottomCenter, child: getAddLocationObjectView()), @@ -248,7 +93,325 @@ )); } - Widget getPositionInfoView() { + //鎺т欢闃村奖 + List<BoxShadow> getViewShadow() { + return [ + BoxShadow( + blurRadius: 6.5, + spreadRadius: 1, + color: Color(0x4D0E96FF), + ) + ]; + } + + //鑾峰彇鍦板浘瑙嗗浘 + Widget getMapView() { + return Container( + child: BMFMapWidget( + onBMFMapCreated: (controller) { + // onBMFMapCreated(controller); + _mapController = controller; + }, + mapOptions: mapOptions, + ), + ); + } + + //娣诲姞鎯冲畾浣嶇殑浜� + Widget getAddLocationObjectView() { + return Container( + alignment: Alignment.topCenter, + height: 72, + margin: const EdgeInsets.fromLTRB(10, 0, 10, 0), + padding: const EdgeInsets.fromLTRB(0, 18, 0, 0), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(10), topRight: Radius.circular(10)), + boxShadow: getViewShadow()), + child: Flex( + direction: Axis.horizontal, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Image.asset( + "assets/images/common/icon_person.png", + height: 17, + ), + Container( + width: 11, + height: 1, + ), + const Text( + "娣诲姞鎯冲畾浣嶇殑瀵硅薄", + style: TextStyle(color: ColorConstant.theme, fontSize: 15), + ) + ], + ), + ); + } + + @override + bool get wantKeepAlive => true; +} + +//鎺т欢闃村奖 +List<BoxShadow> getViewShadow() { + return [ + BoxShadow( + blurRadius: 6.5, + spreadRadius: 1, + color: Color(0x4D0E96FF), + ) + ]; +} + +/*****************瀹氫綅淇℃伅****************/ + +class PositionInfoPage extends StatefulWidget { + PositionInfoPage({Key? key}) : super(key: key); + + @override + _PositionInfoPageState createState() => _PositionInfoPageState(); +} + +class _PositionInfoPageState extends State<PositionInfoPage> + with SingleTickerProviderStateMixin { + //浣嶇疆淇℃伅鏄惁闅愯棌 + bool locationInfoHidden = true; + + @override + Widget build(BuildContext context) { + return Container( + padding: const EdgeInsets.fromLTRB(10, 35, 10, 0), + child: Flex(direction: Axis.vertical, children: [ + //----------鎼滅储妗�-------- + Flex( + direction: Axis.horizontal, + children: [ + Expanded( + child: InkWell( + onTap: () { + print("璺宠浆瀹氫綅"); + }, + child: Container( + alignment: Alignment.center, + padding: EdgeInsets.fromLTRB(13, 0, 13, 0), + height: 45, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + boxShadow: getViewShadow()), + child: Flex( + direction: Axis.horizontal, + children: [ + Image.asset( + "assets/images/main/icon_location_search.png", + height: 19, + ), + Container( + width: 10, + ), + const Expanded( + child: Text("鍦板浘涓婃壘浣嶇疆", + style: TextStyle( + fontSize: 14, + color: Color(0xFFC4CDD1)))) + ], + ), + ))), + InkWell( + onTap: () { + print("sos"); + }, + child: Container( + width: 45, + height: 45, + margin: const EdgeInsets.only(left: 8.5), + decoration: BoxDecoration( + color: Colors.white, + boxShadow: getViewShadow(), + borderRadius: BorderRadius.circular(23)), + alignment: Alignment.center, + child: Image.asset( + "assets/images/main/icon_location_sos.png", + height: 35, + ), + )) + ], + ), + //---------涓汉淇℃伅涓庡畾浣嶄俊鎭�--- + Container( + height: 400, + child: Stack( + children: [ + //浣嶇疆淇℃伅 + getPositionInfoView(context), + //涓汉淇℃伅 + Container( + height: 100, + margin: EdgeInsets.only(top: 10), + padding: EdgeInsets.only(left: 15, top: 8, right: 15), + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + bottomLeft: + Radius.circular(locationInfoHidden ? 10 : 0), + bottomRight: + Radius.circular(locationInfoHidden ? 10 : 0), + topLeft: Radius.circular(10), + topRight: Radius.circular(10)), + color: Colors.white, + boxShadow: getViewShadow()), + child: Stack( + alignment: Alignment.topCenter, + children: [ + Flex( + mainAxisAlignment: MainAxisAlignment.center, + direction: Axis.horizontal, + children: [ + Image.asset( + "assets/images/main/icon_location_change_person.png", + width: 13, + ), + Text( + " 鍒囨崲瀹炴椂瀹氫綅浜�", + style: TextStyle( + color:ColorConstant.theme, fontSize: 15), + ) + ], + ), + //涓汉淇℃伅 + Flex( + direction: Axis.horizontal, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Image.asset( + "assets/images/mine/icon_mine_default_portrait.png", + height: 33, + width: 33, + ), + Container( + width: 5, + ), + Expanded( + child: Flex( + direction: Axis.vertical, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "鎴戣嚜宸�", + softWrap: false, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Color(0xFFA0A0A0), fontSize: 18), + ), + Container( + height: 2, + ), + Text( + "ID:128312", + style: TextStyle( + color: Color(0xFFA0A0A0), fontSize: 12), + ) + ], + )), + Container( + width: 5, + ), + Flex( + direction: Axis.vertical, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + MyOutlineButton( + "鐢熸垚杞ㄨ抗", + 13, + height: 26, + width: 82, + fontSize: 12, + onClick: () { + print("鐢熸垚杞ㄨ抗"); + }, + ), + Container( + height: 6, + ), + MyOutlineButton( + "瀹炴椂鍏变韩", + 13, + height: 26, + width: 82, + fontSize: 12, + onClick: () { + print("瀹炴椂鍏变韩"); + }, + ), + ]) + ], + ) + ], + ), + ), + + //鏇村 + Positioned( + left: MediaQuery.of(context).size.width / 2 - 10 - 70 / 2, + top: 80, + child: InkWell( + onTap: () { + setState(() { + locationInfoHidden = !locationInfoHidden; + }); + }, + child: Container( + width: 70, + height: 40, + child: Stack( + alignment: Alignment.bottomCenter, + children: [ + Container( + height: 30, + width: 60, + margin: EdgeInsets.only(top: 0), + alignment: Alignment.center, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: + BorderRadius.circular(15), + boxShadow: getViewShadow()), + ), + Positioned( + top: 0, + child: Container( + height: 25, + width: 70, + alignment: Alignment.bottomCenter, + + decoration: BoxDecoration( + color: Colors.white, + ), + // child: Text( + // "鏀惰捣", + // style: TextStyle( + // color: ColorConstant.theme, + // fontSize: 11), + // ) + )), + Positioned( + bottom: 5, + child: Text( + locationInfoHidden ? "灞曞紑" : "鏀惰捣", + style: TextStyle( + color:ColorConstant.theme, + fontSize: 11), + )), + ])))) + ], + )), + ])); + } + + Widget getPositionInfoView(BuildContext context) { if (!locationInfoHidden) { return Positioned( top: 110, @@ -355,61 +518,318 @@ return Container(); } } +} - //鎺т欢闃村奖 - List<BoxShadow> getViewShadow() { - return [ - BoxShadow( - blurRadius: 6.5, - spreadRadius: 1, - color: Color(0x4D0E96FF), - ) - ]; +/********************POI鎼滅储********************/ +class LocationSearchPage extends StatefulWidget { + @override + _LocationSearchPageState createState() => _LocationSearchPageState(); +} + +class _LocationSearchPageState extends State<LocationSearchPage> + with SingleTickerProviderStateMixin { + //1-鎼滅储椤甸潰 2-寤鸿鎼滅储椤甸潰 3-缁撴灉灞曠ず椤甸潰 + int state = 1; + + TextEditingController? editingController; + + @override + void initState() { + super.initState(); + editingController = TextEditingController(); } - //鑾峰彇鍦板浘瑙嗗浘 - Widget getMapView() { - return Container( - child: BMFMapWidget( - onBMFMapCreated: (controller) { - // onBMFMapCreated(controller); - }, - mapOptions: mapOptions, + @override + Widget build(BuildContext context) { + return Flex(direction: Axis.vertical, children: [ + //鎼滅储妗� + Container( + margin: EdgeInsets.fromLTRB(10, 35, 10, 11), + alignment: Alignment.center, + padding: EdgeInsets.fromLTRB(8, 0, 8, 0), + height: 45, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + boxShadow: getViewShadow()), + child: Flex( + direction: Axis.horizontal, + children: [ + Image.asset( + "assets/images/map/icon_location_back.png", + height: 30, + ), + Container( + width: 10, + ), + Expanded( + child: TextField( + controller: editingController, + onChanged: (text) { + print(text); + setState(() { + if (text.isNotEmpty) + state = 2; + else + state = 1; + }); + }, + decoration: const InputDecoration( + focusedBorder: InputBorder.none, + border: InputBorder.none, + hintText: "鍦板浘涓婃壘浣嶇疆", + hintStyle: TextStyle(fontSize: 14, color: Color(0xFFC4CDD1))), + )), + InkWell( + child: Container( + padding: EdgeInsets.only(right: 10), + child: Text( + "鎼滅储", + style: TextStyle(color: ColorConstant.theme, fontSize: 15), + )), + ) + ], + ), ), + + Expanded(child: getContentView()) + ]); + } + + Widget getContentView() { + if (state == 1) + return getNotSearchView(); + else if (state == 2) { + return getSearchSuggestView(); + } else + return Container(); + } + + Widget getNotSearchView() { + return Column( + children: [ + Container( + padding: EdgeInsets.only(left: 7, right: 7, bottom: 7, top: 7), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + topRight: Radius.circular(15), topLeft: Radius.circular(15)), + boxShadow: getViewShadow(), + ), + child: Column(mainAxisSize: MainAxisSize.min, children: [ + //鍒嗙被 + Container( + padding: + EdgeInsets.only(left: 20, right: 20, bottom: 15, top: 9), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + getSugguestSearchType( + "閰掑簵", + Image.asset( + "assets/images/map/icon_location_search_type_hotel.png", + height: 34, + ), () { + setSearchKey("閰掑簵"); + }), + getSugguestSearchType( + "椁愰", + Image.asset( + "assets/images/map/icon_location_search_type_eat.png", + height: 34, + ), () { + setSearchKey("椁愰"); + }), + getSugguestSearchType( + "澶栧崠", + Image.asset( + "assets/images/map/icon_location_search_type_waimai.png", + height: 34, + ), () { + setSearchKey("澶栧崠"); + }), + getSugguestSearchType( + "鐢靛奖闄�", + Image.asset( + "assets/images/map/icon_location_search_type_movie.png", + height: 34, + ), () { + setSearchKey("鐢靛奖闄�"); + }), + getSugguestSearchType( + "鏅偣", + Image.asset( + "assets/images/map/icon_location_search_type_sense.png", + height: 34, + ), () { + setSearchKey("鏅偣"); + }), + ], + )), + //骞垮憡 + Container( + height: 210, + ), + ]), + ), + //鍒嗛殧绾� + Container( + height: 10, + color: Color(0xFFF0F0F0), + ), + Expanded( + child: Container( + color: Colors.white, + padding: EdgeInsets.only(left: 20, right: 20), + child: Column( + children: [getHistoryItem("铻嶆亽鐩堝槈涓績-瑗块棬", "閲嶅簡甯傛睙鍖楀尯", 0)], + ), + )) + ], ); } - //娣诲姞鎯冲畾浣嶇殑浜� - Widget getAddLocationObjectView() { + setSearchKey(String key) { + editingController!.text = key; + editingController!.selection = TextSelection( + baseOffset: key.length, extentOffset: editingController!.text.length); + startPOISearch(key); + } + + startPOISearch(String key) async { + BMFPoiNearbySearchOption poiNearbySearchOption = BMFPoiNearbySearchOption( + keywords: <String>[key], + location: BMFCoordinate(40.049557, 116.279295), + isRadiusLimit: false); +// 妫�绱㈠疄渚� + BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch(); +// 妫�绱㈠洖璋� + nearbySearch.onGetPoiNearbySearchResult( + callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) { + print("poi鍛ㄨ竟妫�绱㈠洖璋� errorCode = ${errorCode} result = ${result.toMap()}"); + // 瑙f瀽reslut锛屽叿浣撳弬鑰僤emo + }); +// 鍙戣捣妫�绱� + bool flag = await nearbySearch.poiNearbySearch(poiNearbySearchOption); + } + + //寤鸿鎼滅储瑙嗗浘 + Widget getSearchSuggestView() { return Container( - alignment: Alignment.topCenter, - height: 72, - margin: const EdgeInsets.fromLTRB(10, 0, 10, 0), - padding: const EdgeInsets.fromLTRB(0, 18, 0, 0), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( - topLeft: Radius.circular(10), topRight: Radius.circular(10)), + topLeft: Radius.circular(15), topRight: Radius.circular(15)), boxShadow: getViewShadow()), - child: Flex( - direction: Axis.horizontal, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, + padding: EdgeInsets.fromLTRB(20, 0, 20, 0), + child: ListView( + padding: const EdgeInsets.all(0), children: [ - Image.asset( - "assets/images/common/icon_person.png", - height: 17, - ), - Container( - width: 11, - height: 1, - ), - const Text( - "娣诲姞鎯冲畾浣嶇殑瀵硅薄", - style: TextStyle(color: Color(0xFF0E95FE), fontSize: 15), - ) + getHistoryItem("鏍囬", "鍐呭", 0), + getHistoryItem("鏍囬", "鍐呭", 1), + getHistoryItem("鏍囬", "鍐呭", 2), + getHistoryItem("鏍囬", "鍐呭", 3), + getHistoryItem("鏍囬", "鍐呭", 4), + getHistoryItem("鏍囬", "鍐呭", 5), + getHistoryItem("鏍囬", "鍐呭", 6), + getHistoryItem("鏍囬", "鍐呭", 7), + getHistoryItem("鏍囬", "鍐呭", 8), + getHistoryItem("鏍囬", "鍐呭", 9), ], ), ); } + + //鍘嗗彶璁板綍椤圭洰 + Widget getHistoryItem(String title, String content, int index) { + return InkWell( + onTap: () { + print("鐐瑰嚮:$index"); + }, + child: Container( + height: 67, + decoration: BoxDecoration( + color: Colors.white, + border: const Border( + bottom: BorderSide( + // 璁剧疆鍗曚晶杈规鐨勬牱寮� + color: Color(0xFFF1F2F3), + width: 1, + style: BorderStyle.solid))), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + padding: EdgeInsets.only(top: 12, right: 9), + alignment: Alignment.topCenter, + child: Image.asset( + "assets/images/map/icon_location_location.png", + height: 16, + )), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + title, + softWrap: false, + overflow: TextOverflow.ellipsis, + style: + const TextStyle(color: Color(0xFF333333), fontSize: 13), + ), + Container( + height: 5, + ), + Text( + content, + style: + const TextStyle(color: Color(0xFF9DAAB3), fontSize: 11), + ), + ], + )), + Image.asset( + "assets/images/map/icon_location_position_input.png", + height: 20, + ) + ], + ), + )); + } + + Widget getSugguestSearchType( + String title, Image icon, GestureTapCallback _onClick) { + return InkWell( + onTap: () { + _onClick(); + }, + child: Flex( + direction: Axis.vertical, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + icon, + Container( + height: 5, + ), + Text( + title, + style: const TextStyle(color: Color(0xFF333333), fontSize: 11), + ) + ], + )); + } +} + +/********************浣嶇疆璇︽儏********************/ +class PositionDetailPage extends StatefulWidget { + @override + _PositionDetailPageState createState() => _PositionDetailPageState(); +} + +class _PositionDetailPageState extends State<PositionDetailPage> + with SingleTickerProviderStateMixin { + @override + Widget build(BuildContext context) { + return Container(); + } } -- Gitblit v1.8.0