Showing
4 changed files
with
70 additions
and
16 deletions
lib/apis/api_base.dart
0 → 100644
| 1 | +import 'package:Parlando/apis/api_response.dart'; | ||
| 2 | +import 'package:Parlando/net/dio_utils.dart'; | ||
| 3 | +import 'package:dio/dio.dart'; | ||
| 4 | +import 'package:flutter/material.dart'; | ||
| 5 | + | ||
| 6 | +class BaseApi { | ||
| 7 | + Future<Response<ApiResponse<T>>> post<T>( | ||
| 8 | + String path, { | ||
| 9 | + data, | ||
| 10 | + Map<String, dynamic>? queryParameters, | ||
| 11 | + Options? options, | ||
| 12 | + CancelToken? cancelToken, | ||
| 13 | + ProgressCallback? onSendProgress, | ||
| 14 | + ProgressCallback? onReceiveProgress, | ||
| 15 | + }) { | ||
| 16 | + return _getDio().post<ApiResponse<T>>( | ||
| 17 | + path, | ||
| 18 | + data: data, | ||
| 19 | + queryParameters: queryParameters, | ||
| 20 | + options: options, | ||
| 21 | + cancelToken: cancelToken, | ||
| 22 | + onSendProgress: onSendProgress, | ||
| 23 | + onReceiveProgress: onReceiveProgress, | ||
| 24 | + ); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + Dio _getDio() { | ||
| 28 | + return DioUtils.instance.dio; | ||
| 29 | + } | ||
| 30 | +} |
lib/apis/api_order.dart
0 → 100644
| 1 | +import 'package:Parlando/apis/api_base.dart'; | ||
| 2 | +import 'package:dio/dio.dart'; | ||
| 3 | +import 'package:flutter/material.dart'; | ||
| 4 | + | ||
| 5 | +class OrderApi extends BaseApi { | ||
| 6 | + OrderApi._privateConstructor(); | ||
| 7 | + | ||
| 8 | + static final OrderApi _instance = OrderApi._privateConstructor(); | ||
| 9 | + | ||
| 10 | + static OrderApi get request { | ||
| 11 | + return _instance; | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + Future<Response> createOrder(String productId) { | ||
| 15 | + return post("/order"); | ||
| 16 | + } | ||
| 17 | +} |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | 2 | ||
| 3 | +import 'package:Parlando/apis/api_order.dart'; | ||
| 3 | import 'package:flutter/material.dart'; | 4 | import 'package:flutter/material.dart'; |
| 4 | import 'package:in_app_purchase/in_app_purchase.dart'; | 5 | import 'package:in_app_purchase/in_app_purchase.dart'; |
| 5 | 6 | ||
| ... | @@ -50,6 +51,7 @@ class PaymentSdk { | ... | @@ -50,6 +51,7 @@ class PaymentSdk { |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | buy(ProductDetails details) { | 53 | buy(ProductDetails details) { |
| 54 | + // OrderApi.request.createOrder() | ||
| 53 | final PurchaseParam purchaseParam = PurchaseParam(productDetails: details); | 55 | final PurchaseParam purchaseParam = PurchaseParam(productDetails: details); |
| 54 | if (_isConsumable(details)) { | 56 | if (_isConsumable(details)) { |
| 55 | InAppPurchase.instance.buyConsumable(purchaseParam: purchaseParam); | 57 | InAppPurchase.instance.buyConsumable(purchaseParam: purchaseParam); | ... | ... |
| ... | @@ -21,14 +21,14 @@ class AddressSelectPage extends StatefulWidget { | ... | @@ -21,14 +21,14 @@ class AddressSelectPage extends StatefulWidget { |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | class AddressSelectPageState extends State<AddressSelectPage> { | 23 | class AddressSelectPageState extends State<AddressSelectPage> { |
| 24 | - List<nearby.Results> _list = []; | 24 | + List<nearby.Results> _nearByList = []; |
| 25 | final ScrollController _controller = ScrollController(); | 25 | final ScrollController _controller = ScrollController(); |
| 26 | LatLng? _center; | 26 | LatLng? _center; |
| 27 | late GoogleMapController mapController; | 27 | late GoogleMapController mapController; |
| 28 | bool isLoading = false; | 28 | bool isLoading = false; |
| 29 | Map<MarkerId, Marker> markers = <MarkerId, Marker>{}; | 29 | Map<MarkerId, Marker> markers = <MarkerId, Marker>{}; |
| 30 | late StreamSubscription _locationSubscription; | 30 | late StreamSubscription _locationSubscription; |
| 31 | - String radius = "1000"; | 31 | + String radiusMax = "1000"; |
| 32 | String apiKey = "AIzaSyDQZsMULyO-UtiSht4_MFi1uHT4BIqasjw"; | 32 | String apiKey = "AIzaSyDQZsMULyO-UtiSht4_MFi1uHT4BIqasjw"; |
| 33 | nearby.NearbyPlacesResponse nearbyPlacesResponse = nearby.NearbyPlacesResponse(); | 33 | nearby.NearbyPlacesResponse nearbyPlacesResponse = nearby.NearbyPlacesResponse(); |
| 34 | 34 | ||
| ... | @@ -70,15 +70,18 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -70,15 +70,18 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | void getNearbyPlaces(String keyword) async { | 72 | void getNearbyPlaces(String keyword) async { |
| 73 | - String uri = | 73 | + String host = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json'; |
| 74 | - '${'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${_center?.latitude},${_center?.longitude}&radius=$radius'}&key=$apiKey&keyword=$keyword'; | 74 | + String location = 'location=${_center?.latitude},${_center?.longitude}'; |
| 75 | + String radius = 'radius=$radiusMax'; | ||
| 76 | + String types = 'type=point_of_interest'; | ||
| 77 | + String uri = '${'$host?$location&$radius'}&key=$apiKey&keyword=$keyword&$types'; | ||
| 75 | print(uri); | 78 | print(uri); |
| 76 | var url = Uri.parse(uri); | 79 | var url = Uri.parse(uri); |
| 77 | var response = await http.post(url); | 80 | var response = await http.post(url); |
| 78 | nearbyPlacesResponse = nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body)); | 81 | nearbyPlacesResponse = nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body)); |
| 79 | - _list = nearbyPlacesResponse.results!; | 82 | + _nearByList = nearbyPlacesResponse.results!; |
| 80 | - if (_list.isNotEmpty) { | 83 | + if (_nearByList.isNotEmpty) { |
| 81 | - selectItemLocation(_list[0]); | 84 | + selectItemLocation(_nearByList[0]); |
| 82 | } | 85 | } |
| 83 | setState(() { | 86 | setState(() { |
| 84 | isLoading = false; | 87 | isLoading = false; |
| ... | @@ -102,13 +105,13 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -102,13 +105,13 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 102 | var loaderView = const GFLoader().expanded(flex: 11); | 105 | var loaderView = const GFLoader().expanded(flex: 11); |
| 103 | var realList = ListView.separated( | 106 | var realList = ListView.separated( |
| 104 | controller: _controller, | 107 | controller: _controller, |
| 105 | - itemCount: _list.length, | 108 | + itemCount: _nearByList.length, |
| 106 | separatorBuilder: (_, index) => const Divider(), | 109 | separatorBuilder: (_, index) => const Divider(), |
| 107 | itemBuilder: (_, index) { | 110 | itemBuilder: (_, index) { |
| 108 | - var item = _list[index]; | 111 | + var item = _nearByList[index]; |
| 109 | return _AddressItem( | 112 | return _AddressItem( |
| 110 | isSelected: item.isSelect, | 113 | isSelected: item.isSelect, |
| 111 | - date: item, | 114 | + data: item, |
| 112 | onTap: () { | 115 | onTap: () { |
| 113 | selectItemLocation(item); | 116 | selectItemLocation(item); |
| 114 | }, | 117 | }, |
| ... | @@ -130,6 +133,8 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -130,6 +133,8 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 130 | onMapCreated: _onMapCreated, | 133 | onMapCreated: _onMapCreated, |
| 131 | initialCameraPosition: CameraPosition(target: _center ?? const LatLng(45.521563, -122.677433), zoom: 16.0), | 134 | initialCameraPosition: CameraPosition(target: _center ?? const LatLng(45.521563, -122.677433), zoom: 16.0), |
| 132 | markers: Set<Marker>.of(markers.values), | 135 | markers: Set<Marker>.of(markers.values), |
| 136 | + myLocationEnabled: true, | ||
| 137 | + myLocationButtonEnabled: true, | ||
| 133 | ).expanded(flex: 9); | 138 | ).expanded(flex: 9); |
| 134 | 139 | ||
| 135 | return Scaffold( | 140 | return Scaffold( |
| ... | @@ -144,7 +149,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -144,7 +149,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 144 | initButton() { | 149 | initButton() { |
| 145 | return MyButton( | 150 | return MyButton( |
| 146 | onPressed: () { | 151 | onPressed: () { |
| 147 | - var selected = _list.where((element) => element.isSelect); | 152 | + var selected = _nearByList.where((element) => element.isSelect); |
| 148 | if (selected.isEmpty) { | 153 | if (selected.isEmpty) { |
| 149 | Toast.show('未选择地址!'); | 154 | Toast.show('未选择地址!'); |
| 150 | return; | 155 | return; |
| ... | @@ -158,7 +163,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -158,7 +163,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 158 | 163 | ||
| 159 | void buildMarkers() { | 164 | void buildMarkers() { |
| 160 | markers.clear(); | 165 | markers.clear(); |
| 161 | - for (var value in _list) { | 166 | + for (var value in _nearByList) { |
| 162 | final MarkerId markerId = MarkerId(buildMarkerId(value)); | 167 | final MarkerId markerId = MarkerId(buildMarkerId(value)); |
| 163 | final Marker marker = Marker( | 168 | final Marker marker = Marker( |
| 164 | icon: value.isSelect ? BitmapDescriptor.defaultMarker : BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueBlue), | 169 | icon: value.isSelect ? BitmapDescriptor.defaultMarker : BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueBlue), |
| ... | @@ -183,7 +188,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -183,7 +188,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 183 | } | 188 | } |
| 184 | 189 | ||
| 185 | void selectItemLocation(nearby.Results item) { | 190 | void selectItemLocation(nearby.Results item) { |
| 186 | - for (var element in _list) { | 191 | + for (var element in _nearByList) { |
| 187 | element.isSelect = false; | 192 | element.isSelect = false; |
| 188 | } | 193 | } |
| 189 | item.isSelect = true; | 194 | item.isSelect = true; |
| ... | @@ -201,12 +206,12 @@ class AddressSelectPageState extends State<AddressSelectPage> { | ... | @@ -201,12 +206,12 @@ class AddressSelectPageState extends State<AddressSelectPage> { |
| 201 | class _AddressItem extends StatelessWidget { | 206 | class _AddressItem extends StatelessWidget { |
| 202 | const _AddressItem({ | 207 | const _AddressItem({ |
| 203 | Key? key, | 208 | Key? key, |
| 204 | - required this.date, | 209 | + required this.data, |
| 205 | this.isSelected = false, | 210 | this.isSelected = false, |
| 206 | this.onTap, | 211 | this.onTap, |
| 207 | }) : super(key: key); | 212 | }) : super(key: key); |
| 208 | 213 | ||
| 209 | - final nearby.Results date; | 214 | + final nearby.Results data; |
| 210 | final bool isSelected; | 215 | final bool isSelected; |
| 211 | final GestureTapCallback? onTap; | 216 | final GestureTapCallback? onTap; |
| 212 | 217 | ||
| ... | @@ -220,7 +225,7 @@ class _AddressItem extends StatelessWidget { | ... | @@ -220,7 +225,7 @@ class _AddressItem extends StatelessWidget { |
| 220 | height: 50.0, | 225 | height: 50.0, |
| 221 | child: Row( | 226 | child: Row( |
| 222 | children: <Widget>[ | 227 | children: <Widget>[ |
| 223 | - Text('${date.name} ${date.vicinity}').expanded(), | 228 | + Text('${data.name}').expanded(), |
| 224 | Visibility(visible: isSelected, child: const Icon(Icons.done, color: Colors.blue)) | 229 | Visibility(visible: isSelected, child: const Icon(Icons.done, color: Colors.blue)) |
| 225 | ], | 230 | ], |
| 226 | ), | 231 | ), | ... | ... |
-
Please register or login to post a comment