Skip to content

feat(*): add layers widgets#542

Closed
ruizalexandre wants to merge 1 commit into
fleaflet:masterfrom
ruizalexandre:feature/layer-widgets
Closed

feat(*): add layers widgets#542
ruizalexandre wants to merge 1 commit into
fleaflet:masterfrom
ruizalexandre:feature/layer-widgets

Conversation

@ruizalexandre

Copy link
Copy Markdown

⚠️ BREAKING CHANGES

  • No more layer options definition (REMOVED)
  • No more plugin API (REMOVED)

🔥 All layers become flutter widgets !


  • Add shared mapState widget
  • Improve rebuild layers
  • mapState API available on your custom widget with var mapState = MapStateInheritedWidget.of(context).mapState;
  • Update example with new strategy
  • Add simultation of user location

@ruizalexandre

ruizalexandre commented Mar 6, 2020

Copy link
Copy Markdown
Author

@johnpryan @synw

Closes #535
Closes #459
Closes #482

⚠️
Old plugins no more compatible. need a quick update to move on Flutter Widget


🚀 Working with 0.9.0 of flutter_map

@porfirioribeiro

Copy link
Copy Markdown
Contributor

This seems very interesting, will be watching this!

@ruizalexandre

Copy link
Copy Markdown
Author

Hi @ibrierley
Moving your plugin to this new logic can take much time ?
https://github.com/ibrierley/flutter_map_dragmarker

@ibrierley

Copy link
Copy Markdown
Contributor

This should do it I think...

https://github.com/ibrierley/flutter_map_dragmarker/blob/master/lib/dragmarker_widget_layer.dart

There's 2 files in there, dragmarker.dart for the old plugin format, and dragmarker_widget_layer.dart for the referenced one here.

It would be good to hear whether this format will likely become the new standard, as I'll convert my tile layer code as well to it at some point if so.

@lehno

lehno commented Apr 10, 2020

Copy link
Copy Markdown

I would use that

@ruizalexandre

ruizalexandre commented Apr 11, 2020

Copy link
Copy Markdown
Author

@lehno @johnpryan

PR updated
Working with 0.9.0, tested on iPhone 6, 11 and Google Pixel 3 📱

[BREAKING CHANGES]
No more layer options definition (REMOVED)
No more plugin API (REMOVED)

[FEATURE]
All layers become flutter widgets !

- Add shared mapState widget
- Improve rebuild layers
- mapState API available with MapStateInheritedWidget.of(context).mapState;
- Update example with new strategy
- Add simultation of user location
@ruizalexandre

Copy link
Copy Markdown
Author

@johnpryan I updated file names on my PR, that's why the build failed

@ruizalexandre

Copy link
Copy Markdown
Author

First of all - I love using Widgets instead of declarative options for the layers. Great job.

I think MapStateInheritedWidget is a mouthful and it can be moved to MapState class itself, so you can do MapState.of(context) and get the state instance. Because of that this static method should directly lookup the inherited widget, then return the mapState instead of the widget itself:

My suggestion:

class MapState {
  ...
  static MapState of(BuildContext context, {bool nullOk = false}) {
    assert(context != null);
    assert(nullOk != null);
    final widget = context.dependOnInheritedWidgetOfExactType<MapStateInheritedWidget>();
    if (nullOk || widget != null) {
      return widget?.mapState;
    }
    throw FlutterError('MapState.of() called with a context that does not contain a FlutterMap.');
  }
}

Not necessary, but given this InheritedWidget won't be useful by itself it can become a hidden widget - _MapStateInheritedWidget.

Second suggestion - to get this to be even considered to be merged with flutter_map there should be a way for the two approaches to coexist (at least initially):

  • layers should remain a list of declarative options;
  • introduce children to the FlutterMap which can use the widgets;
  • ensure layers or children is null - less complexity is better;
  • if the layers are present and children are null - then create the children automatically;
  • I think plugins can only work with layers, but am not 100% sure.

Thanks @avioli !
I'll change my PR to take care about your return. 🔥

@Sly2024

Sly2024 commented May 11, 2020

Copy link
Copy Markdown

Any update on this PR?
The proposed approach to work with widget is way more efficient and easier to use

@ruizalexandre

Copy link
Copy Markdown
Author

@Sly2024 I need to finish my last update
Build pipeline is blocked because I've updated file names !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants