Advertisement
Dordzhiev

Untitled

Jan 30th, 2023
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.31 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:geocoding/geocoding.dart';
  3.  
  4. import '../../../../../../shared/services/geocoding_service.dart';
  5. import '../../../../../../shared/view/loading_text/loading_text.dart';
  6.  
  7. class AddressRow extends StatelessWidget {
  8.   const AddressRow({
  9.     Key? key,
  10.     required this.leading,
  11.     required this.address,
  12.     this.anotherApplicationButton = false,
  13.     this.selectable = false,
  14.   }) : super(key: key);
  15.   final Widget leading;
  16.   final String address;
  17.   final bool anotherApplicationButton;
  18.   final bool selectable;
  19.  
  20.   @override
  21.   Widget build(BuildContext context) {
  22.     late Widget text;
  23.     if (selectable) {
  24.       text = SelectableText(
  25.         address,
  26.         style: const TextStyle(color: Color(0xFF616161)),
  27.       );
  28.     } else {
  29.       text = Text(
  30.         address,
  31.         style: const TextStyle(color: Color(0xFF616161)),
  32.       );
  33.     }
  34.     return Row(
  35.       children: [
  36.         Expanded(
  37.           child: Row(
  38.             crossAxisAlignment: CrossAxisAlignment.start,
  39.             children: [
  40.               leading,
  41.               const SizedBox(width: 8.0),
  42.               Expanded(
  43.                 child: text,
  44.               ),
  45.             ],
  46.           ),
  47.         ),
  48.         if (anotherApplicationButton)
  49.           AnotherApplicationButton(address: address),
  50.       ],
  51.     );
  52.   }
  53. }
  54.  
  55. class AnotherApplicationButton extends StatelessWidget {
  56.   const AnotherApplicationButton({
  57.     Key? key,
  58.     required this.address,
  59.   }) : super(key: key);
  60.  
  61.   final String address;
  62.  
  63.   @override
  64.   Widget build(BuildContext context) {
  65.     return FutureBuilder<List<Location>>(
  66.       future: GeocodingService.locationFromAddress(address),
  67.       builder: (context, snapshot) {
  68.         if (snapshot.connectionState != ConnectionState.done) {
  69.           return const LoadingTextComponent();
  70.         } else {
  71.           if (snapshot.data!.isEmpty) {
  72.             return const SizedBox.shrink();
  73.           }
  74.           return TextButton(
  75.             onPressed: GeocodingService.openLocationByAnotherApplication(
  76.               snapshot.data!,
  77.             ),
  78.             child: const Text(
  79.               'ПЕРЕЙТИ В КАРТЫ',
  80.               style: TextStyle(fontWeight: FontWeight.bold),
  81.             ),
  82.           );
  83.         }
  84.       },
  85.     );
  86.   }
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement