mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Place tracker/maintenance (#519)
* format place_tracker README * update sentence in README * sort Dart members, remove unnecessary type declarations * Run place_tracker on Android and iOS, update project files * add link to developer preview caveat * grammar * update MAINTENANCE
This commit is contained in:
@@ -7,6 +7,9 @@ import 'place.dart';
|
||||
import 'stub_data.dart';
|
||||
|
||||
class PlaceDetails extends StatefulWidget {
|
||||
final Place place;
|
||||
final ValueChanged<Place> onChanged;
|
||||
|
||||
const PlaceDetails({
|
||||
@required this.place,
|
||||
@required this.onChanged,
|
||||
@@ -15,9 +18,6 @@ class PlaceDetails extends StatefulWidget {
|
||||
assert(onChanged != null),
|
||||
super(key: key);
|
||||
|
||||
final Place place;
|
||||
final ValueChanged<Place> onChanged;
|
||||
|
||||
@override
|
||||
PlaceDetailsState createState() => PlaceDetailsState();
|
||||
}
|
||||
@@ -26,10 +26,37 @@ class PlaceDetailsState extends State<PlaceDetails> {
|
||||
Place _place;
|
||||
GoogleMapController _mapController;
|
||||
final Set<Marker> _markers = {};
|
||||
|
||||
final TextEditingController _nameController = TextEditingController();
|
||||
final TextEditingController _descriptionController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('${_place.name}'),
|
||||
backgroundColor: Colors.green[700],
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 8.0, 0.0),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.save, size: 30.0),
|
||||
onPressed: () {
|
||||
widget.onChanged(_place);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: GestureDetector(
|
||||
onTap: () {
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
},
|
||||
child: _detailsBody(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_place = widget.place;
|
||||
@@ -38,20 +65,10 @@ class PlaceDetailsState extends State<PlaceDetails> {
|
||||
return super.initState();
|
||||
}
|
||||
|
||||
void _onMapCreated(GoogleMapController controller) {
|
||||
_mapController = controller;
|
||||
setState(() {
|
||||
_markers.add(Marker(
|
||||
markerId: MarkerId(_place.latLng.toString()),
|
||||
position: _place.latLng,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
Widget _detailsBody() {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.fromLTRB(24.0, 12.0, 24.0, 12.0),
|
||||
children: <Widget>[
|
||||
children: [
|
||||
_NameTextField(
|
||||
controller: _nameController,
|
||||
onChanged: (value) {
|
||||
@@ -87,68 +104,21 @@ class PlaceDetailsState extends State<PlaceDetails> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('${_place.name}'),
|
||||
backgroundColor: Colors.green[700],
|
||||
actions: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 8.0, 0.0),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.save, size: 30.0),
|
||||
onPressed: () {
|
||||
widget.onChanged(_place);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: GestureDetector(
|
||||
onTap: () {
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
},
|
||||
child: _detailsBody(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NameTextField extends StatelessWidget {
|
||||
const _NameTextField({
|
||||
@required this.controller,
|
||||
@required this.onChanged,
|
||||
Key key,
|
||||
}) : assert(controller != null),
|
||||
assert(onChanged != null),
|
||||
super(key: key);
|
||||
|
||||
final TextEditingController controller;
|
||||
final ValueChanged<String> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 16.0),
|
||||
child: TextField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Name',
|
||||
labelStyle: TextStyle(fontSize: 18.0),
|
||||
),
|
||||
style: const TextStyle(fontSize: 20.0, color: Colors.black87),
|
||||
autocorrect: true,
|
||||
controller: controller,
|
||||
onChanged: (value) {
|
||||
onChanged(value);
|
||||
},
|
||||
),
|
||||
);
|
||||
void _onMapCreated(GoogleMapController controller) {
|
||||
_mapController = controller;
|
||||
setState(() {
|
||||
_markers.add(Marker(
|
||||
markerId: MarkerId(_place.latLng.toString()),
|
||||
position: _place.latLng,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _DescriptionTextField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
|
||||
final ValueChanged<String> onChanged;
|
||||
const _DescriptionTextField({
|
||||
@required this.controller,
|
||||
@required this.onChanged,
|
||||
@@ -157,9 +127,6 @@ class _DescriptionTextField extends StatelessWidget {
|
||||
assert(onChanged != null),
|
||||
super(key: key);
|
||||
|
||||
final TextEditingController controller;
|
||||
final ValueChanged<String> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
@@ -181,38 +148,12 @@ class _DescriptionTextField extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _StarBar extends StatelessWidget {
|
||||
const _StarBar({
|
||||
@required this.rating,
|
||||
@required this.onChanged,
|
||||
Key key,
|
||||
}) : assert(rating != null && rating >= 0 && rating <= maxStars),
|
||||
assert(onChanged != null),
|
||||
super(key: key);
|
||||
|
||||
static const int maxStars = 5;
|
||||
final int rating;
|
||||
final ValueChanged<int> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(maxStars, (index) {
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.star),
|
||||
iconSize: 40.0,
|
||||
color: rating > index ? Colors.amber : Colors.grey[400],
|
||||
onPressed: () {
|
||||
onChanged(index + 1);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Map extends StatelessWidget {
|
||||
final LatLng center;
|
||||
|
||||
final GoogleMapController mapController;
|
||||
final ArgumentCallback<GoogleMapController> onMapCreated;
|
||||
final Set<Marker> markers;
|
||||
const _Map({
|
||||
@required this.center,
|
||||
@required this.mapController,
|
||||
@@ -223,24 +164,19 @@ class _Map extends StatelessWidget {
|
||||
assert(onMapCreated != null),
|
||||
super(key: key);
|
||||
|
||||
final LatLng center;
|
||||
final GoogleMapController mapController;
|
||||
final ArgumentCallback<GoogleMapController> onMapCreated;
|
||||
final Set<Marker> markers;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
elevation: 4.0,
|
||||
elevation: 4,
|
||||
child: SizedBox(
|
||||
width: 340.0,
|
||||
height: 240.0,
|
||||
width: 340,
|
||||
height: 240,
|
||||
child: GoogleMap(
|
||||
onMapCreated: onMapCreated,
|
||||
initialCameraPosition: CameraPosition(
|
||||
target: center,
|
||||
zoom: 16.0,
|
||||
zoom: 16,
|
||||
),
|
||||
markers: markers,
|
||||
zoomGesturesEnabled: false,
|
||||
@@ -253,78 +189,55 @@ class _Map extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _NameTextField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
|
||||
final ValueChanged<String> onChanged;
|
||||
const _NameTextField({
|
||||
@required this.controller,
|
||||
@required this.onChanged,
|
||||
Key key,
|
||||
}) : assert(controller != null),
|
||||
assert(onChanged != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 0, 0, 16),
|
||||
child: TextField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Name',
|
||||
labelStyle: TextStyle(fontSize: 18),
|
||||
),
|
||||
style: const TextStyle(fontSize: 20, color: Colors.black87),
|
||||
autocorrect: true,
|
||||
controller: controller,
|
||||
onChanged: (value) {
|
||||
onChanged(value);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Reviews extends StatelessWidget {
|
||||
const _Reviews({
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
Widget _buildSingleReview(String reviewText) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10.0),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 80.0,
|
||||
height: 80.0,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(40.0),
|
||||
border: Border.all(
|
||||
width: 3.0,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const <Widget>[
|
||||
Text(
|
||||
'5',
|
||||
style: TextStyle(
|
||||
fontSize: 24.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.star,
|
||||
color: Colors.amber,
|
||||
size: 36.0,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16.0),
|
||||
Expanded(
|
||||
child: Text(
|
||||
reviewText,
|
||||
style: const TextStyle(fontSize: 20.0, color: Colors.black87),
|
||||
maxLines: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Divider(
|
||||
height: 8.0,
|
||||
color: Colors.grey[700],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 8.0),
|
||||
padding: EdgeInsets.fromLTRB(0, 12, 0, 8),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Text(
|
||||
'Reviews',
|
||||
style: TextStyle(
|
||||
fontSize: 24.0,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
decoration: TextDecoration.underline,
|
||||
color: Colors.black87,
|
||||
@@ -340,4 +253,90 @@ class _Reviews extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSingleReview(String reviewText) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(40),
|
||||
border: Border.all(
|
||||
width: 3,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Text(
|
||||
'5',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.star,
|
||||
color: Colors.amber,
|
||||
size: 36,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
reviewText,
|
||||
style: const TextStyle(fontSize: 20, color: Colors.black87),
|
||||
maxLines: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Divider(
|
||||
height: 8,
|
||||
color: Colors.grey[700],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StarBar extends StatelessWidget {
|
||||
static const int maxStars = 5;
|
||||
|
||||
final int rating;
|
||||
final ValueChanged<int> onChanged;
|
||||
const _StarBar({
|
||||
@required this.rating,
|
||||
@required this.onChanged,
|
||||
Key key,
|
||||
}) : assert(rating != null && rating >= 0 && rating <= maxStars),
|
||||
assert(onChanged != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(maxStars, (index) {
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.star),
|
||||
iconSize: 40,
|
||||
color: rating > index ? Colors.amber : Colors.grey[400],
|
||||
onPressed: () {
|
||||
onChanged(index + 1);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user