Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OnePoem
/
OnePoem-App
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Chad
2022-10-31 20:56:50 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
31f8fa2b4346d57e10b5a530dec77cfe94a75341
31f8fa2b
1 parent
24c6e0de
优化代码
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
100 deletions
lib/extension/widget_ext.dart
lib/poem/page/select_address_page.dart
pubspec.lock
lib/extension/widget_ext.dart
0 → 100644
View file @
31f8fa2
import
'package:flutter/material.dart'
;
import
'package:hostex_flutter/generated/l10n.dart'
;
import
'package:hostex_flutter/generated/assets.dart'
;
import
'package:hostex_flutter/ui/extension/widget_ext.dart'
;
extension
WidgetExt
on
Widget
{
Expanded
expanded
({
int
flex
=
1
})
{
return
Expanded
(
flex:
flex
,
child:
this
);
}
SafeArea
safe
()
{
return
SafeArea
(
child:
this
);
}
}
lib/poem/page/select_address_page.dart
View file @
31f8fa2
import
'dart:async'
;
import
'dart:convert'
;
import
'package:Parlando/extension/widget_ext.dart'
;
import
'package:Parlando/models/nearby_response.dart'
as
nearby
;
import
'package:Parlando/routers/fluro_navigator.dart'
;
import
'package:Parlando/util/log_utils.dart'
;
import
'package:Parlando/util/toast_utils.dart'
;
import
'package:flutter/material.dart'
;
import
'package:Parlando/widgets/my_button.dart'
;
...
...
@@ -30,8 +32,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
late
StreamSubscription
_locationSubscription
;
String
radius
=
"1000"
;
String
apiKey
=
"AIzaSyDQZsMULyO-UtiSht4_MFi1uHT4BIqasjw"
;
nearby
.
NearbyPlacesResponse
nearbyPlacesResponse
=
nearby
.
NearbyPlacesResponse
();
nearby
.
NearbyPlacesResponse
nearbyPlacesResponse
=
nearby
.
NearbyPlacesResponse
();
@override
void
dispose
()
{
...
...
@@ -65,9 +66,10 @@ class AddressSelectPageState extends State<AddressSelectPage> {
}
}
_locationSubscription
=
location
.
onLocationChanged
.
listen
((
LocationData
currentLocation
)
{
_locationSubscription
=
location
.
onLocationChanged
.
listen
((
LocationData
currentLocation
)
{
_center
=
LatLng
(
currentLocation
.
latitude
!,
currentLocation
.
longitude
!);
Log
.
e
(
"currentLocation.latitude
${currentLocation.latitude}
"
);
getNearbyPlaces
(
""
);
});
}
...
...
@@ -76,8 +78,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
'
${'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${_center.latitude}
,
${_center.longitude}
&radius=
$radius
'
}&
key
=
$apiKey
&
keyword
=
$keyword
';
var url = Uri.parse(uri);
var response = await http.post(url);
nearbyPlacesResponse =
nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body));
nearbyPlacesResponse = nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body));
_list = nearbyPlacesResponse.results!;
setState(() {
isLoading = false;
...
...
@@ -100,68 +101,68 @@ class AddressSelectPageState extends State<AddressSelectPage> {
getNearbyPlaces("");
}
void _goToCurrentCenter() {
mapController.animateCamera(CameraUpdate.newLatLng(_center));
}
@override
Widget build(BuildContext context) {
var loaderView = const GFLoader().expanded(flex: 11);
var realList = ListView.separated(
controller: _controller,
itemCount: _list.length,
separatorBuilder: (_, index) => const Divider(),
itemBuilder: (_, index) {
return _AddressItem(
isSelected: _index == index,
date: _list[index],
onTap: () {
_index = index;
setState(() {});
},
);
},
).expanded(flex: 11);
var listHolder = isLoading ? loaderView : realList;
var searchBar = SearchBar(
hintText: '
搜索地址
',
onPressed: (text) async {
isLoading = true;
_controller.animateTo(0.0, duration: const Duration(milliseconds: 10), curve: Curves.ease);
_index = 0;
// 构造检索参数
getNearbyPlaces(text);
},
);
var map = GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(target: _center, zoom: 16.0),
markers: Set<Marker>.of(markers.values),
).expanded(flex: 9);
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: SearchBar(
hintText: '
搜索地址
',
onPressed: (text) async {
isLoading = true;
_controller.animateTo(0.0,
duration: const Duration(milliseconds: 10), curve: Curves.ease);
_index = 0;
// 构造检索参数
getNearbyPlaces(text);
},
),
body: SafeArea(
child: Column(
children: <Widget>[
Expanded(
flex: 9,
child: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 16.0,
),
markers: Set<Marker>.of(markers.values),
),
),
Expanded(
flex: 11,
child: isLoading
? const GFLoader()
: ListView.separated(
controller: _controller,
itemCount: _list.length,
separatorBuilder: (_, index) => const Divider(),
itemBuilder: (_, index) {
return _AddressItem(
isSelected: _index == index,
date: _list[index],
onTap: () {
_index = index;
setState(() {});
},
);
},
),
),
MyButton(
onPressed: () {
if (_list.isEmpty) {
Toast.show('
未选择地址!
');
return;
}
NavigatorUtils.goBackWithParams(context, _list[_index]);
},
text: '
确认选择地址
',
)
],
),
),
appBar: searchBar,
body: Column(
children: <Widget>[
map,
listHolder,
initButton(),
],
).safe(),
);
}
initButton() {
return MyButton(
onPressed: () {
if (_list.isEmpty) {
Toast.show('
未选择地址!
');
return;
}
NavigatorUtils.goBackWithParams(context, _list[_index]);
},
text: '
确认选择地址
',
);
}
}
...
...
@@ -173,6 +174,7 @@ class _AddressItem extends StatelessWidget {
this.isSelected = false,
this.onTap,
}) : super(key: key);
final nearby.Results date;
final bool isSelected;
final GestureTapCallback? onTap;
...
...
@@ -187,15 +189,8 @@ class _AddressItem extends StatelessWidget {
height: 50.0,
child: Row(
children: <Widget>[
Expanded(
child: Text(
'
$
{
date
.
name
}
$
{
date
.
vicinity
}
',
),
),
Visibility(
visible: isSelected,
child: const Icon(Icons.done, color: Colors.blue),
)
Text('
$
{
date
.
name
}
$
{
date
.
vicinity
}
').expanded(),
Visibility(visible: isSelected, child: const Icon(Icons.done, color: Colors.blue))
],
),
),
...
...
pubspec.lock
View file @
31f8fa2
...
...
@@ -28,7 +28,7 @@ packages:
name: archive
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.
3.0
"
version: "3.
1.11
"
args:
dependency: transitive
description:
...
...
@@ -42,7 +42,7 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.
9.0
"
version: "2.
8.2
"
boolean_selector:
dependency: transitive
description:
...
...
@@ -112,21 +112,21 @@ packages:
name: cached_network_image
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.2.
2
"
version: "3.2.
1
"
cached_network_image_platform_interface:
dependency: transitive
description:
name: cached_network_image_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "
2
.0.0"
version: "
1
.0.0"
cached_network_image_web:
dependency: transitive
description:
name: cached_network_image_web
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.
2
"
version: "1.0.
1
"
camera:
dependency: "direct main"
description:
...
...
@@ -168,7 +168,14 @@ packages:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.1"
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
checked_yaml:
dependency: transitive
description:
...
...
@@ -189,7 +196,7 @@ packages:
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.
1
"
version: "1.1.
0
"
code_builder:
dependency: transitive
description:
...
...
@@ -224,7 +231,7 @@ packages:
name: coverage
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.
5
.0"
version: "1.
2
.0"
cross_file:
dependency: transitive
description:
...
...
@@ -238,7 +245,7 @@ packages:
name: crypto
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.
2
"
version: "3.0.
1
"
csslib:
dependency: transitive
description:
...
...
@@ -336,7 +343,7 @@ packages:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.
1
"
version: "1.3.
0
"
ffi:
dependency: transitive
description:
...
...
@@ -463,7 +470,7 @@ packages:
name: flutter_native_splash
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.
10+1
"
version: "2.2.
9
"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
...
...
@@ -757,6 +764,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.1.0"
lint:
dependency: transitive
description:
name: lint
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
lints:
dependency: transitive
description:
...
...
@@ -805,21 +819,21 @@ packages:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.1
2
"
version: "0.12.1
1
"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.
5
"
version: "0.1.
4
"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.
8
.0"
version: "1.
7
.0"
mime:
dependency: transitive
description:
...
...
@@ -868,7 +882,7 @@ packages:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.
2
"
version: "1.8.
1
"
path_provider:
dependency: "direct main"
description:
...
...
@@ -1272,7 +1286,7 @@ packages:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.
9.0
"
version: "1.
8.2
"
sp_util:
dependency: transitive
description:
...
...
@@ -1293,7 +1307,7 @@ packages:
name: sqflite
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.
1.0
+1"
version: "2.
0.3
+1"
sqflite_common:
dependency: transitive
description:
...
...
@@ -1335,14 +1349,14 @@ packages:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.
1
"
version: "1.1.
0
"
sync_http:
dependency: transitive
description:
name: sync_http
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.
1
"
version: "0.3.
0
"
synchronized:
dependency: transitive
description:
...
...
@@ -1363,28 +1377,28 @@ packages:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.
1
"
version: "1.2.
0
"
test:
dependency: "direct dev"
description:
name: test
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.21.
4
"
version: "1.21.
1
"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.
12
"
version: "0.4.
9
"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.1
6
"
version: "0.4.1
3
"
timing:
dependency: transitive
description:
...
...
@@ -1405,7 +1419,7 @@ packages:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.
1
"
version: "1.3.
0
"
universal_io:
dependency: transitive
description:
...
...
@@ -1538,7 +1552,7 @@ packages:
name: vm_service
url: "https://pub.flutter-io.cn"
source: hosted
version: "
9.0.0
"
version: "
8.2.2
"
wakelock:
dependency: "direct main"
description:
...
...
@@ -1659,5 +1673,5 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.1
8
.0 <3.0.0"
flutter: ">=3.
3
.0"
dart: ">=2.1
7
.0 <3.0.0"
flutter: ">=3.
0
.0"
...
...
Please
register
or
login
to post a comment