Closed batyanko closed 4 years ago
hi, why you want to show map as item in navigationBar ?
Yeah it is supposed to be a simple app of a business. You know, first tab is some info, second tab for example photos, and third tab is "Contacts".
Something like your widget would fit very nicely in "Contacts", but it needs to init on the address of the business (and not the user's location).
Now I tried to put the Widget in a very simple second screen class. Calling it with Navigator.push
, it opens but result is the same - sending me to the users location instead of the init location.
Where should I put the Widget so that it works? So I can start from there...
look to this example :
import 'package:flutter/material.dart';
import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';
class SimpleExample extends StatefulWidget {
SimpleExample({Key key}) : super(key: key);
@override
_SimpleExampleState createState() => _SimpleExampleState();
}
class _SimpleExampleState extends State<SimpleExample> {
PageController controller;
int indexPage;
@override
void initState() {
super.initState();
controller = PageController(initialPage: 1);
indexPage = controller.initialPage;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("osm"),
),
body: PageView(
children: <Widget>[
Center(
child: Text("page n1"),
),
SimpleOSM(),
],
controller: controller,
onPageChanged: (p) {
setState(() {
indexPage = p;
});
},
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: indexPage,
onTap: (p) {
controller.animateToPage(p,
duration: Duration(milliseconds: 500), curve: Curves.linear);
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.info),
title: Text("information"),
),
BottomNavigationBarItem(
icon: Icon(Icons.contacts), title: Text("contact")),
],
),
);
}
}
class SimpleOSM extends StatefulWidget {
@override
State<StatefulWidget> createState() =>SimpleOSMState();
}
class SimpleOSMState extends State<SimpleOSM> with AutomaticKeepAliveClientMixin {
GlobalKey<OSMFlutterState> osmKey;
@override
void initState() {
super.initState();
osmKey = GlobalKey<OSMFlutterState>();
}
@override
Widget build(BuildContext context) {
return OSMFlutter(
key: osmKey,
currentLocation: false,
markerIcon: MarkerIcon(
icon: Icon(
Icons.person_pin_circle,
color: Colors.blue,
size: 56,
),
),
trackMyPosition: false,
initPosition: GeoPoint(latitude: 42.151753, longitude: 24.769730),
useSecureURL: false,
);
}
@override
bool get wantKeepAlive => true;
}
Thanks for the effort (and for the page controller, that's useful)
I put this in a new file and invoke it with Navigator.push
.
It works, but the same problem is there - it brings me to Silicon Valley again :)) (default device location of the Emulator).
Should I invoke this with anything other than Navigator.push
?
i tested in my phone and it's worked fine , i will do more test to find problem try to run the app with real device and tell me if the problem still exist.
Hi, I am trying to show a
GeoPoint
asinitPosition
, but theOSMFlutter
widget persists showing user's location when loading. (Actually it seems to show theGeoPoint
position for a few ms, then going directly to user's location) A related problem is the app asking for location permission, which I prefer to keep off for now.currentLocation
andtrackMyPosition
are both set to false.I am showing the widget in the following way, invoked as a
BottomNavigationBarItem
:The project is quite small, you can try it yourself: https://github.com/batyanko/table-tennis-club/commit/a5b227b773d8985408e54065d5c2f0cb4e5e2dc2
Tested on Galaxy S7 and the API 30 Emulator (w/GooglePlay)
Note: I am new to Flutter, might have done various things wrong. Let me know.