| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- import 'dart:io';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/src/widgets/framework.dart';
- import 'package:flutter_map/flutter_map.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import 'package:get/get_core/src/get_main.dart';
- import 'package:location/base/base_page.dart';
- import 'package:location/resource/assets.gen.dart';
- import 'package:location/resource/colors.gen.dart';
- import 'package:location/resource/string.gen.dart';
- import 'package:location/utils/common_expand.dart';
- import 'package:pull_to_refresh/pull_to_refresh.dart';
- import 'package:sliding_sheet2/sliding_sheet2.dart';
- import '../../../router/app_pages.dart';
- import '../../../utils/common_util.dart';
- import '../../../widget/common_view.dart';
- import 'common_point_select_address_controller.dart';
- class CommonPointSelectAddressPage
- extends BasePage<CommonPointSelectAddressController> {
- const CommonPointSelectAddressPage({super.key});
- static start() {
- Get.toNamed(RoutePath.commonPointSelectAddress);
- }
- @override
- bool immersive() {
- return true;
- }
- @override
- Widget buildBody(BuildContext context) {
- return PopScope(
- canPop: false,
- onPopInvokedWithResult: (bool didPop, dynamic result) {
- if (didPop) {
- return;
- }
- controller.backClick();
- },
- child: Stack(
- children: [
- buildMapView(),
- buildHeadBgView(),
- buildMapLogoView(),
- buildLocationFunView(),
- buildSlidingSheetView(),
- buildToolbarView(),
- ],
- ),
- );
- }
- Widget buildLocationFunView() {
- return Obx(() {
- return Positioned(
- right: 12.w,
- bottom: 0.48.sh + controller.sheetProgress * 0.48.sh,
- child: Opacity(
- opacity: 1 - controller.sheetProgress,
- child: GestureDetector(
- onTap: controller.moveToCurrentLocation,
- child: Container(
- width: 38.w,
- height: 38.w,
- decoration: BoxDecoration(
- color: ColorName.white,
- borderRadius: BorderRadius.circular(10.r),
- boxShadow: [
- BoxShadow(
- color: ColorName.black10,
- blurRadius: 16,
- spreadRadius: 2,
- offset: Offset(0, 4.w),
- ),
- ],
- ),
- child: Center(
- child: Assets.images.iconCurrentLocation
- .image(width: 20.w, height: 20.w),
- )),
- ),
- ),
- );
- });
- }
- Widget buildMapLogoView() {
- return Visibility(
- visible: Platform.isAndroid,
- child: Obx(() {
- return Positioned(
- left: 12.w,
- bottom: 0.465.sh + controller.sheetProgress * 0.48.sh,
- child: Opacity(
- opacity: 1 - controller.sheetProgress,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Assets.images.iconAmapLogo.image(height: 20.w),
- Text(StringName.locationAmapCo,
- style: TextStyle(
- fontSize: 9.sp, color: '#666666'.color, height: 1))
- ],
- ),
- ));
- }),
- );
- }
- Widget buildSlidingSheetView() {
- return SizedBox(
- width: double.infinity,
- height: 1.sh,
- child: SlidingSheet(
- listener: (SheetState state) {
- controller.setSheetProgress(state.progress);
- },
- controller: controller.sheetController,
- color: ColorName.transparent,
- elevation: 0,
- shadowColor: ColorName.transparent,
- cornerRadius: 0,
- snapSpec: SnapSpec(
- initialSnap: 0.45,
- // Enable snapping. This is true by default.
- snap: true,
- // Set custom snapping points.
- snappings: [0.45, 0.94],
- // Define to what the snappings relate to. In this case,
- // the total available space that the sheet can expand to.
- positioning: SnapPositioning.relativeToAvailableSpace,
- ),
- headerBuilder: selectAddressHeaderBuilder,
- customBuilder: selectAddressCustomBuilder),
- );
- }
- Widget buildToolbarView() {
- return SafeArea(
- child: Container(
- padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 14.5.w),
- child: Row(
- children: [
- GestureDetector(
- onTap: controller.backClick,
- child: CommonView.getBackBtnView()),
- Spacer(),
- GestureDetector(
- onTap: controller.onSelectAddressDone,
- child: Container(
- width: 50.w,
- height: 28.w,
- decoration: BoxDecoration(
- color: ColorName.white,
- borderRadius: BorderRadius.circular(8.r),
- ),
- child: Center(
- child: Text(StringName.selectAddressDone,
- style: TextStyle(
- fontSize: 12.sp,
- color: ColorName.black90,
- fontWeight: FontWeight.bold)),
- )),
- ),
- ],
- ),
- ),
- );
- }
- Widget buildHeadBgView() {
- return IgnorePointer(
- child: AspectRatio(
- aspectRatio: 360 / 146,
- child: Assets.images.bgCommonPointSelectAddressTop.image(
- width: double.infinity,
- ),
- ),
- );
- }
- Widget selectAddressCustomBuilder(BuildContext context,
- ScrollController scrollController, SheetState state) {
- return Container(
- color: Colors.white,
- height: double.infinity,
- child: SmartRefresher(
- enablePullUp: true,
- enablePullDown: false,
- controller: controller.refreshController,
- onLoading: controller.onLoadMorePoiData,
- child: CustomScrollView(
- controller: scrollController,
- slivers: [
- SliverToBoxAdapter(child: buildRangeCenterLocationView()),
- Obx(() {
- return SliverList.builder(
- itemBuilder: (ctx, index) =>
- buildPoiSearchItem(controller.poiList[index]),
- itemCount: controller.poiList.length);
- })
- ],
- ),
- ),
- );
- }
- Widget buildRangeCenterLocationView() {
- return Container(
- decoration: BoxDecoration(
- color: '#F2F5FE'.color,
- borderRadius: BorderRadius.circular(8.r),
- border: Border.all(
- color: '#D0D9F4'.color,
- width: 0.5.w,
- ),
- ),
- margin: EdgeInsets.only(left: 12.w, right: 12.w, bottom: 8.w, top: 4.w),
- padding: EdgeInsets.symmetric(horizontal: 13.w, vertical: 8.w),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- margin: EdgeInsets.only(top: 3.w),
- child:
- Assets.images.iconSelectCurrentLocation.image(width: 10.w)),
- SizedBox(width: 8.w),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(StringName.currentLocation,
- style: TextStyle(
- fontSize: 12.sp,
- color: ColorName.black90,
- fontWeight: FontWeight.bold)),
- SizedBox(height: 4.w),
- Obx(() {
- return Text(
- controller.currentRangeCenterLocation?.address ??
- StringName.selectAddressPlease,
- style:
- TextStyle(fontSize: 10.sp, color: ColorName.black50));
- })
- ],
- )
- ],
- ),
- );
- }
- Widget selectAddressHeaderBuilder(BuildContext context, SheetState state) {
- return IntrinsicHeight(
- child: Column(
- children: [
- buildRangeView(),
- SizedBox(height: 12.w),
- buildSelectAddressView()
- ],
- ),
- );
- }
- Widget buildSelectAddressView() {
- return GestureDetector(
- onTap: controller.onOpenSearchAddressModel,
- child: Container(
- padding: EdgeInsets.all(12.w),
- width: double.infinity,
- decoration: BoxDecoration(
- color: ColorName.white,
- borderRadius: BorderRadius.only(
- topLeft: Radius.circular(18.r),
- topRight: Radius.circular(18.r))),
- child: Obx(() {
- return Container(
- width: double.infinity,
- height: 40.w,
- decoration: BoxDecoration(
- border: controller.sheetProgress == 1
- ? Border.all(color: '#EAECEE'.color, width: 0.5.w)
- : null,
- color: '#F6F6F8'.color,
- borderRadius: BorderRadius.circular(8.r)),
- child: Row(
- children: [
- SizedBox(width: 12.w),
- Assets.images.iconCommonPointSearch
- .image(width: 14.w, height: 14.w),
- SizedBox(width: 6.w),
- Expanded(
- child: TextField(
- enabled: controller.sheetProgress == 1,
- controller: controller.searchEditController,
- focusNode: controller.searchFocusNode,
- style: TextStyle(
- fontSize: 14.sp, color: ColorName.primaryTextColor),
- maxLines: 1,
- maxLength: 30,
- keyboardType: TextInputType.text,
- textAlignVertical: TextAlignVertical.center,
- textInputAction: TextInputAction.next,
- onChanged: (txt) => controller.onSearchTextChange(txt),
- decoration: InputDecoration(
- hintText:
- StringName.selectAddressPleaseEnterPlaceName,
- counterText: '',
- hintStyle: TextStyle(
- fontSize: 13.sp, color: ColorName.black40),
- contentPadding: const EdgeInsets.all(0),
- border: const OutlineInputBorder(
- borderSide: BorderSide.none)))),
- SizedBox(width: 12.w),
- ],
- ),
- );
- }),
- ),
- );
- }
- Widget buildRangeView() {
- return Obx(() {
- return Opacity(
- opacity: 1 - controller.sheetProgress,
- child: Container(
- width: 336.w,
- height: 41.w,
- decoration: BoxDecoration(
- color: ColorName.white,
- borderRadius: BorderRadius.circular(12.r)),
- child: Builder(builder: (context) {
- return Row(
- children: [
- SizedBox(width: 16.w),
- Text(StringName.selectAddressCommonlyUsedRange,
- style:
- TextStyle(fontSize: 12.sp, color: ColorName.black80)),
- SizedBox(width: 8.w),
- Expanded(
- child: SliderTheme(
- data: SliderTheme.of(context).copyWith(
- thumbColor: Colors.white,
- thumbShape: CustomBlueThumb(
- thumbRadius: 4.6.w,
- outerRingWidth: 2.5.w,
- color: ColorName.colorPrimary,
- ),
- overlayShape: SliderComponentShape.noOverlay,
- trackHeight: 6.w,
- activeTrackColor: ColorName.colorPrimary,
- inactiveTrackColor: "#E4E4E4".color,
- trackShape: CustomTrackShape(),
- ),
- child: Obx(() {
- return Slider(
- value: controller.commonPointRange,
- min: 50,
- max: 500,
- onChanged: (value) {
- controller.setCommonPointRange(value);
- },
- onChangeStart: (value) {
- controller.setCommonPointRangeStart();
- },
- onChangeEnd: (value) {
- controller.setCommonPointRangeEnd();
- },
- );
- }),
- ),
- ),
- SizedBox(width: 8.w),
- Container(
- width: 48.w,
- height: 21.w,
- decoration: BoxDecoration(
- color: '#F6F6F8'.color,
- borderRadius: BorderRadius.circular(5.w)),
- child: Center(child: Obx(() {
- return Text(
- '${controller.commonPointRange.toInt()}m',
- style:
- TextStyle(fontSize: 12.sp, color: ColorName.black80),
- );
- })),
- ),
- SizedBox(width: 16.w),
- ],
- );
- }),
- ),
- );
- });
- }
- Widget buildMapView() {
- return SizedBox(
- width: double.infinity,
- height: 0.65.sh,
- child: Stack(
- children: [
- MapWidget(controller: controller.mapController),
- Center(
- child: Container(
- width: 18.w,
- height: 18.w,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: ColorName.colorPrimary,
- border: Border.all(color: ColorName.white, width: 2.w),
- ),
- ),
- )
- ],
- ));
- }
- Widget buildPoiSearchItem(PoiItem item) {
- return GestureDetector(
- onTap: () {
- controller.onPoiItemClick(item);
- },
- child: Container(
- margin: EdgeInsets.only(left: 12.w, right: 12.w, bottom: 8.w, top: 4.w),
- padding: EdgeInsets.only(left: 13.w, top: 8.w, bottom: 8.w),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- margin: EdgeInsets.only(top: 3.w),
- child: Assets.images.iconPoiLocation.image(width: 10.w)),
- SizedBox(width: 8.w),
- Expanded(
- child: IntrinsicHeight(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- Expanded(
- child: Text(item.title ?? '',
- overflow: TextOverflow.ellipsis,
- style: TextStyle(
- fontSize: 12.sp,
- color: ColorName.black90,
- fontWeight: FontWeight.bold)),
- ),
- SizedBox(width: 16.w),
- buildDistanceTextView(item)
- ],
- ),
- SizedBox(height: 4.w),
- Text(item.address ?? '',
- style: TextStyle(
- fontSize: 10.sp, color: ColorName.black50))
- ],
- ),
- ),
- )
- ],
- ),
- ),
- );
- }
- Widget buildDistanceTextView(PoiItem item) {
- final location = controller.mineUserInfo.lastLocation.value;
- if (location == null ||
- location.latitude == null ||
- location.longitude == null ||
- item.longitude == null ||
- item.latitude == null) {
- return SizedBox.shrink();
- }
- final distance = MapUtil.calculateLineDistance(location.longitude!,
- location.latitude!, item.longitude!, item.latitude!);
- return Text(MapUtil.format(distance),
- style: TextStyle(fontSize: 10.sp, color: ColorName.black30));
- }
- }
- class CustomTrackShape extends RoundedRectSliderTrackShape {
- @override
- Rect getPreferredRect({
- required RenderBox parentBox,
- Offset offset = Offset.zero,
- required SliderThemeData sliderTheme,
- bool isEnabled = false,
- bool isDiscrete = false,
- }) {
- final trackHeight = sliderTheme.trackHeight;
- final trackLeft = offset.dx;
- final trackTop = offset.dy + (parentBox.size.height - trackHeight!) / 2;
- final trackWidth = parentBox.size.width;
- return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
- }
- }
- class CustomBlueThumb extends SliderComponentShape {
- final double thumbRadius;
- final double outerRingWidth;
- final Color color;
- const CustomBlueThumb({
- this.thumbRadius = 12.0,
- this.outerRingWidth = 3.0,
- this.color = const Color(0xFF4476FF),
- });
- @override
- Size getPreferredSize(bool isEnabled, bool isDiscrete) {
- return Size.fromRadius(thumbRadius + outerRingWidth);
- }
- @override
- void paint(
- PaintingContext context,
- Offset center, {
- required Animation<double> activationAnimation,
- required Animation<double> enableAnimation,
- required bool isDiscrete,
- required TextPainter labelPainter,
- required RenderBox parentBox,
- required SliderThemeData sliderTheme,
- required TextDirection textDirection,
- required double value,
- required double textScaleFactor,
- required Size sizeWithOverflow,
- }) {
- final Canvas canvas = context.canvas;
- final Paint outerPaint = Paint()
- ..color = color // 使用您指定的蓝色
- ..strokeWidth = outerRingWidth
- ..style = PaintingStyle.stroke;
- final Paint innerPaint = Paint()
- ..color = Colors.white
- ..style = PaintingStyle.fill;
- // 绘制蓝色外圈
- canvas.drawCircle(center, thumbRadius + outerRingWidth / 2, outerPaint);
- // 绘制白色内圆
- canvas.drawCircle(center, thumbRadius, innerPaint);
- }
- }
|