Skip to content

Commit

Permalink
#15: Refactor MapPage and added lint analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanrashid52 committed Nov 5, 2019
1 parent 358893c commit e20dcc7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 18 deletions.
18 changes: 18 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include: package:pedantic/analysis_options.yaml

analyzer:
exclude:
- lib/src/locations.g.dart

linter:
rules:
- always_declare_return_types
- camel_case_types
- empty_constructor_bodies
- annotate_overrides
- avoid_init_to_null
- constant_identifier_names
- one_member_abstracts
- slash_for_doc_comments
- sort_constructors_first
- unnecessary_brace_in_string_interps
16 changes: 15 additions & 1 deletion lib/pages/map/map_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import 'dart:async';

import 'package:flutter_app/bloc/bloc_provider.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class MapBloc extends BlocBase {
StreamController<MapType> _mapTypeController =
StreamController<MapType>.broadcast();

Stream<MapType> get mayType => _mapTypeController.stream;

@override
void dispose() {}
void dispose() {
_mapTypeController.close();
}

void setMayType(MapType mayType) {
_mapTypeController.sink.add(mayType);
}
}
50 changes: 33 additions & 17 deletions lib/pages/map/map_page.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import 'dart:async';

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

class MapPage extends StatefulWidget {
@override
_MapPageState createState() => _MapPageState();
}

class _MapPageState extends State<MapPage> {
Completer<GoogleMapController> _controller = Completer();
class MapPage extends StatelessWidget {
final Completer<GoogleMapController> _controller = Completer();

static final CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(37.42796133580664, -122.085749655962),
Expand All @@ -24,21 +21,40 @@ class _MapPageState extends State<MapPage> {

@override
Widget build(BuildContext context) {
final MapBloc mapBloc = BlocProvider.of(context);
return new Scaffold(
appBar: AppBar(
title: Text("Maps"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.satellite),
onPressed: () => mapBloc.setMayType(MapType.satellite),
),
IconButton(
icon: Icon(Icons.map),
onPressed: () => mapBloc.setMayType(MapType.normal),
),
IconButton(
icon: Icon(Icons.dashboard),
onPressed: () => mapBloc.setMayType(MapType.terrain),
),
],
),
body: GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
),
floatingActionButton: FloatingActionButton.extended(
body: StreamBuilder<MapType>(
stream: mapBloc.mayType,
initialData: MapType.hybrid,
builder: (context, snapshot) {
return GoogleMap(
mapType: snapshot.data,
initialCameraPosition: _kGooglePlex,
zoomGesturesEnabled: true,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
);
}),
floatingActionButton: FloatingActionButton(
onPressed: _goToTheLake,
label: Text('To the lake!'),
icon: Icon(Icons.directions_boat),
),
);
}
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies:
path_provider: ^0.4.1
rxdart: ^0.19.0
google_maps_flutter: ^0.5.21+8
http: ^0.12.0+1
json_serializable: ^2.0.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit e20dcc7

Please sign in to comment.