Skip to content

Commit

Permalink
#15: Creating Place Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanrashid52 committed Nov 16, 2019
1 parent 620da3c commit 19e341d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/pages/map/map_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';

class MapBloc extends BlocBase {
MapBloc(this.placesApiService) {
_fetchLocations("Mumbai");
_fetchLocations("A");
}

final PlacesApiService placesApiService;
Expand Down
78 changes: 41 additions & 37 deletions lib/pages/map/map_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_app/bloc/bloc_provider.dart';
import 'package:flutter_app/pages/map/map_bloc.dart';
import 'package:flutter_app/pages/map/place_widget.dart';
import 'package:flutter_app/pages/places/places_models.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

Expand All @@ -13,6 +13,9 @@ class MapPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final MapBloc mapBloc = BlocProvider.of(context);

_createMapTypeListener(mapBloc.mayType);

return Scaffold(
appBar: AppBar(
title: Text("Maps"),
Expand All @@ -33,50 +36,43 @@ class MapPage extends StatelessWidget {
),
body: Stack(
children: <Widget>[
StreamBuilder<MapType>(
stream: mapBloc.mayType,
initialData: MapType.hybrid,
builder: (context, snapshotType) {
return GoogleMap(
mapType: snapshotType.data,
initialCameraPosition: buildInitialCamera(),
zoomGesturesEnabled: true,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
);
},
Container(
child: StreamBuilder<MapType>(
stream: mapBloc.mayType,
initialData: MapType.hybrid,
builder: (context, snapshotType) {
return buildGoogleMap(snapshotType.data);
},
),
),
//TODO: Fix the scroll and item are not visible
StreamBuilder<List<Candidate>>(
stream: mapBloc.offices,
builder: (context, snapshot) {
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
var item = snapshot.data[index];
/*return ListTile(
leading: CircleAvatar(
backgroundColor: Colors.red,
child: Text("P"),
),
title: Text(item.name),
subtitle: Text(item.name),
);*/
return Text(
item.name,
style: Theme.of(context).textTheme.headline,
);
},
);
},
Container(
child: StreamBuilder<List<Candidate>>(
stream: mapBloc.offices,
builder: (context, snapshot) {
if (snapshot.hasData) {
return PlaceWidget(snapshot.data);
}
return CircularProgressIndicator();
},
),
)
],
),
);
}

GoogleMap buildGoogleMap(MapType mayType) {
return GoogleMap(
mapType: mayType,
initialCameraPosition: buildInitialCamera(),
zoomGesturesEnabled: true,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
);
}

/*Set<Marker> buildMarkerSet(List<Office> offices) {
Set<Marker> markers = Set<Marker>();
for (var office in offices) {
Expand All @@ -91,4 +87,12 @@ class MapPage extends StatelessWidget {
zoom: 14.4746,
);
}

void _createMapTypeListener(Stream<MapType> mayType) {
mayType.listen((value) {
if (_controller != null) {
// _controller
}
});
}
}
32 changes: 32 additions & 0 deletions lib/pages/map/place_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:flutter_app/pages/places/places_models.dart';

class PlaceWidget extends StatelessWidget {
PlaceWidget(this.candidates);

final List<Candidate> candidates;

@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: candidates.length,
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemBuilder: (context, index) {
var item = candidates[index];
return SizedBox(
width: MediaQuery.of(context).size.width,
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.red,
child: Text("P"),
),
title: Text(item.name),
subtitle: Text(item.formatted_address),
),
);
},
);
;
}
}

0 comments on commit 19e341d

Please sign in to comment.