You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
281 lines
9.1 KiB
281 lines
9.1 KiB
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
import 'package:location/location.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:teso/providers/pageAnimations.dart';
|
|
import '../Classes/TesoShop.dart';
|
|
import 'Sub_Pages/CoinPurchase.dart';
|
|
import 'package:teso/providers/user_provider.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
class Home extends StatefulWidget {
|
|
final Function showUploads;
|
|
final Function toggle;
|
|
const Home({Key key, this.showUploads, this.toggle}) : super(key: key);
|
|
@override
|
|
_HomeState createState() => _HomeState(showUploads: this.showUploads);
|
|
}
|
|
|
|
class _HomeState extends State<Home> with TickerProviderStateMixin {
|
|
Function showUploads;
|
|
_HomeState({this.showUploads});
|
|
String title = "Home";
|
|
double titleSize = 45.0;
|
|
String mapstyle;
|
|
var _future;
|
|
static LatLng _initialPosition;
|
|
Set<Marker> markers = {};
|
|
List<TesoShop> shops;
|
|
GoogleMapController mapController;
|
|
static const double CAMERA_ZOOM = 13.499910354614258;
|
|
Location location = Location();
|
|
String routingMessage = "Finding shops....";
|
|
LocationData _location;
|
|
// ignore: unused_field
|
|
String _error;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
SharedPreferences.getInstance().then((prefs) async {
|
|
String currentTheme = prefs.getString("theme");
|
|
if (currentTheme == "dark") {
|
|
rootBundle.loadString('assets/styles/dark.txt').then((string) {
|
|
mapstyle = string;
|
|
});
|
|
} else {
|
|
rootBundle.loadString('assets/styles/light.txt').then((string) {
|
|
mapstyle = string;
|
|
});
|
|
}
|
|
bool first =
|
|
prefs.getBool("launched") != null ? prefs.getBool("launched") : false;
|
|
if (!first) {
|
|
prefs.setBool("launched", true);
|
|
}
|
|
});
|
|
_future = _determinePosition(context);
|
|
location.onLocationChanged.listen((LocationData cLoc) {
|
|
_initialPosition = LatLng(cLoc.latitude, cLoc.longitude);
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
Future<LatLng> _determinePosition(context) async {
|
|
setState(() {
|
|
_error = null;
|
|
});
|
|
try {
|
|
final LocationData _locationResult = await location.getLocation();
|
|
setState(() {
|
|
_location = _locationResult;
|
|
_initialPosition = LatLng(_location.latitude, _location.longitude);
|
|
});
|
|
|
|
// await getLocations();
|
|
return _initialPosition;
|
|
} on PlatformException catch (err) {
|
|
setState(() {
|
|
_error = err.code;
|
|
});
|
|
return _initialPosition;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
//appBar: buildAppBar(context),
|
|
body: FutureBuilder(
|
|
future: _future,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return buildStaleMap(context);
|
|
} else {
|
|
return buildMap(context);
|
|
}
|
|
}),
|
|
);
|
|
}
|
|
|
|
Widget buildAppBar(BuildContext context) {
|
|
return PreferredSize(
|
|
child: Material(
|
|
//elevation: 0.4,
|
|
child: AppBar(
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
automaticallyImplyLeading: false,
|
|
title: Consumer<UserProvider>(builder:
|
|
(BuildContext context, UserProvider value, Widget child) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: TextStyle(
|
|
color: Theme.of(context).primaryColorLight,
|
|
fontFamily: 'DeadheadScript',
|
|
fontSize: titleSize,
|
|
letterSpacing: 3.0,
|
|
),
|
|
),
|
|
Container(
|
|
height: 30,
|
|
child: Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
PageTransition(
|
|
type: PageTransitionType.downToUp,
|
|
child: Coins(
|
|
initalPage: 0,
|
|
),
|
|
),
|
|
),
|
|
child: Image(
|
|
image: AssetImage("assets/images/gold1.png"),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
PageTransition(
|
|
type: PageTransitionType.downToUp,
|
|
child: Coins(initalPage: 0),
|
|
),
|
|
),
|
|
child: Container(
|
|
margin: EdgeInsets.only(left: 2),
|
|
child: Center(
|
|
child: Text(
|
|
value.currentUser != null
|
|
? value.currentUser.gold
|
|
: "0",
|
|
style: TextStyle(
|
|
fontSize: 13.5,
|
|
color: Theme.of(context).primaryColorLight,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
PageTransition(
|
|
type: PageTransitionType.downToUp,
|
|
child: Coins(initalPage: 1),
|
|
),
|
|
),
|
|
child: Image(
|
|
image: AssetImage("assets/images/silver1.png"),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
PageTransition(
|
|
type: PageTransitionType.downToUp,
|
|
child: Coins(initalPage: 1),
|
|
),
|
|
),
|
|
child: Container(
|
|
margin: EdgeInsets.only(left: 2),
|
|
child: Center(
|
|
child: Text(
|
|
value.currentUser != null
|
|
? value.currentUser.silver
|
|
: "0",
|
|
style: TextStyle(
|
|
fontSize: 13.5,
|
|
color: Theme.of(context).primaryColorLight,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
preferredSize: Size.fromHeight(50.0));
|
|
}
|
|
|
|
Widget buildMap(BuildContext context) {
|
|
return GoogleMap(
|
|
// padding: EdgeInsets.only(
|
|
// top: 70.0,
|
|
// ),
|
|
zoomGesturesEnabled: true,
|
|
zoomControlsEnabled: false,
|
|
compassEnabled: true,
|
|
myLocationButtonEnabled: true,
|
|
myLocationEnabled: true,
|
|
// markers: markers,
|
|
initialCameraPosition: CameraPosition(
|
|
target: _initialPosition,
|
|
zoom: CAMERA_ZOOM,
|
|
//bearing: CAMERA_BEARING,
|
|
),
|
|
onMapCreated: (GoogleMapController controller) {
|
|
controller.setMapStyle(mapstyle);
|
|
mapController = controller;
|
|
},
|
|
onCameraMove: (position) {
|
|
setState(() {
|
|
try {
|
|
_initialPosition =
|
|
LatLng(position.target.latitude, position.target.longitude);
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
});
|
|
},
|
|
// polylines: Set<Polyline>.of(polylines.values),
|
|
);
|
|
}
|
|
|
|
Widget buildStaleMap(BuildContext context) {
|
|
return GoogleMap(
|
|
// padding: EdgeInsets.only(
|
|
// top: 70.0,
|
|
// ),
|
|
zoomGesturesEnabled: true,
|
|
zoomControlsEnabled: false,
|
|
compassEnabled: true,
|
|
myLocationButtonEnabled: true,
|
|
myLocationEnabled: true,
|
|
markers: markers,
|
|
initialCameraPosition: CameraPosition(
|
|
target: LatLng(6.700071, -1.630783),
|
|
zoom: CAMERA_ZOOM,
|
|
//bearing: CAMERA_BEARING,
|
|
),
|
|
onMapCreated: (GoogleMapController controller) {
|
|
controller.setMapStyle(mapstyle);
|
|
mapController = controller;
|
|
},
|
|
onCameraMove: (position) {
|
|
setState(() {
|
|
try {
|
|
_initialPosition =
|
|
LatLng(position.target.latitude, position.target.longitude);
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
});
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|