Updating widgets and Offstage()

142 views
Skip to first unread message

Eric Knudstrup

unread,
Sep 9, 2019, 6:04:02 AM9/9/19
to Flutter Development (flutter-dev)
I have an app I'm working on.  I'm using BottomNavigationBar() with a Google Map and several other screens.  It seems to me as if using Offstage() works better with the Google Map.  
Without the Offstage() widget encapsulation, the Map widget loads several PNG icons which don't load until after I tap one of the markers and go to a detail widget screen for the marker and return to the map.  Until I do that, it uses the default Bitmap.  I was thinking about moving the PNG loading into the model?
With the Offstage() encapsulation, the screens won't update when the model receives data.  I'm using Provider and ChangeNotifier.
I was wondering if I need to use a Stream from the model to the different views with an Offstage() widget.

Andy Greenshaw

unread,
Sep 9, 2019, 7:25:11 AM9/9/19
to Flutter Development (flutter-dev), Eric Knudstrup
Just make sure all bitmap icons are loaded before you display the map.
If in a Stateful widget, you can just do (load all your icons, this just loads one)

  BitmapDescriptor _myIcon;

  @override
  void initState() {
    super.initState();
    loadIcons();
  }

  loadIcons() async {
    _myIcon = await BitmapDescriptor.fromAssetImage(
        ImageConfiguration(size: Size(48, 48)), 'images/my_icon.bmp’);
    print('Loaded my icons…’);
  }

Probably best to add them to the provider, so they are available everywhere.
Also, make sure google_maps_flutter is the latest version.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/16cc4020-8bdd-409e-bdbe-1922c170269c%40googlegroups.com.

Eric Knudstrup

unread,
Sep 10, 2019, 6:14:25 AM9/10/19
to Flutter Development (flutter-dev)
I got the PNG marker icons to show up correctly by loading them in the Provider.
It still doesn't seem to want to resize them very much, but I have greater problems to solve.
Had to back off from using the Offstage() container, but I guess I'll have to do some reading.
At least now I almost have an app that I can use, so I can start deciding what I actually want the app to do.

Eric Knudstrup

unread,
Sep 10, 2019, 7:07:10 AM9/10/19
to Flutter Development (flutter-dev)
I resized all of my markers in GIMP, but only one is changed in the Map widget.  Strange...

Eric Knudstrup

unread,
Jan 11, 2020, 2:18:33 AM1/11/20
to Flutter Development (flutter-dev)
I have my custom bitmap markers working.  I loaded them in my model as you suggested.  Except they don't behave uniformly on different Android devices. BitmapDescriptor.fromAssetImage() doesn't seem to be paying attention to the size I gave it in the ImageConfiguration() constructor.  I haven't tried to run it on my iPhone or iPad yet.
On my LG V20, they are tiny.  On my Samsung Galaxy A6, much more visible.  Like I had them on the native iOS version of the app.
Still not sure how to get google_maps_flutter to work with Provider.  Provider expects stateless widgets, but for the level of control I want, google_maps_flutter wants a stateful widget?
Reply all
Reply to author
Forward
0 new messages