Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You can't put a row in a MapPlugin #108

Closed
lsaudon opened this issue Sep 17, 2018 · 2 comments
Closed

You can't put a row in a MapPlugin #108

lsaudon opened this issue Sep 17, 2018 · 2 comments

Comments

@lsaudon
Copy link
Contributor

lsaudon commented Sep 17, 2018

I'm trying to have a row that contains a textfield and a iconButton like the one below.

body: Column(
        children: <Widget>[
          Flexible(
            child: new FlutterMap(
              mapController: mapController,
              options: new MapOptions(
                center: new LatLng(47.10347, 5.48075),
                zoom: 5.0,
                plugins: [
                  new SearchBarPlugin(),
                ],
              ),
              layers: [
                new TileLayerOptions(
                  urlTemplate:
                      "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
                  subdomains: ['a', 'b', 'c'],
                ),
                new SearchBarPluginOptions(
                    TextField(
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        hintText: 'Saisissez votre recherche',
                      ),
                    ),
                    IconButton(
                      icon: Icon(
                        Icons.my_location,
                        color: Color.fromRGBO(0, 178, 169, 1.0),
                      ),
                      onPressed: () {},
                    )),
              ],
            ),
          ),
        ],
      ),
class SearchBarPluginOptions extends LayerOptions {
  final TextField textField;
  final IconButton iconButton;

  SearchBarPluginOptions(this.textField, this.iconButton);
}

class SearchBarPlugin implements MapPlugin {
  @override
  Widget createLayer(LayerOptions options, MapState mapState) {
    if (options is SearchBarPluginOptions) {
      return Row(
        children: <Widget>[
          Container(
            decoration: BoxDecoration(
              color: Color.fromRGBO(255, 255, 255, 0.9),
              borderRadius: BorderRadius.circular(25.0),
            ),
            margin: EdgeInsets.all(15.0),
            padding: EdgeInsets.symmetric(horizontal: 20.0),
            child: options.textField,
          ),
          Container(
            decoration: BoxDecoration(
              color: Color.fromRGBO(255, 255, 255, 0.9),
              borderRadius: BorderRadius.circular(25.0),
            ),
            margin: EdgeInsets.all(15.0),
            child: options.iconButton,
          ),
        ],
      );
    }
    throw ("Unknown options type for MyCustom plugin: $options");
  }

  @override
  bool supportsLayer(LayerOptions options) {
    return options is SearchBarPluginOptions;
  }
}

I have the following errors.

flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performLayout():
flutter: BoxConstraints forces an infinite width.

I don't know if it's a bug or a parameter that's missing on my side.

@lsaudon lsaudon changed the title 🐛 You can't put a row in a MapPlugin Bug: You can't put a row in a MapPlugin Sep 17, 2018
@lsaudon
Copy link
Contributor Author

lsaudon commented Sep 17, 2018

Solution: I wrap a container in Flexible Widget

return Row(
        children: <Widget>[
          Flexible(
            child: Container(
              decoration: BoxDecoration(
                color: Color.fromRGBO(255, 255, 255, 0.9),
                borderRadius: BorderRadius.circular(25.0),
              ),
              margin: EdgeInsets.all(15.0),
              padding: EdgeInsets.symmetric(horizontal: 20.0),
              child: options.textField,
            ),
          ),
          Container(
            decoration: BoxDecoration(
              color: Color.fromRGBO(255, 255, 255, 0.9),
              borderRadius: BorderRadius.circular(25.0),
            ),
            margin: EdgeInsets.all(15.0),
            child: options.iconButton,
          ),
        ],
      );

@lsaudon lsaudon closed this as completed Sep 17, 2018
@alfanhui
Copy link
Contributor

Can OP edit his original post to remove the links, it is linking all the github issues into this one.

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

No branches or pull requests

2 participants