Как отобразить TextFormField поверх GoogleMap, не заполняя весь экран во Flutter? - PullRequest
0 голосов
/ 22 января 2020

Я хочу показать TextFormField и кнопку отправки в верхней части экрана над GoogleMap, но она заполняет весь экран и скрывает карту ниже. Я получаю следующую ошибку, которая, как я знаю, связана с высотой содержимого родительского элемента, равной бесконечности:

У дочерних элементов RenderFlex ненулевое сгибание, но входящие ограничения по высоте не ограничены.

В своем виджете _buildForm () я обернул форму в контейнер с добавленной высотой: 100.0, но я все еще получаю сообщение об ошибке.

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:manchester_maps/locale/locales.dart';

void main() => runApp(CampusForm());

class CampusForm extends StatefulWidget {
  @override
  _CampusFormState createState() => _CampusFormState();
}

class _CampusFormState extends State<CampusForm> {
  final _formKey = GlobalKey<_CampusFormState>();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        // A class which loads the translations from JSON files
        AppLocalizationsDelegate(),
        // Built-in localization of basic text for Material screens
        GlobalMaterialLocalizations.delegate,
        // Built-in localization for text direction LTR/RTL
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        Locale('en', ''),
        Locale('fr', ''),
        Locale('ar', ''),
        Locale('de', ''),
        Locale('es', ''),
        Locale('hi', ''),
        Locale('zh', ''),
        Locale('ja', '')
      ],
      home: Scaffold(
        body: _buildForm(),
      ),
    );
  }

  Widget _buildSearchField() {
    return Expanded(
      child: TextFormField(
        decoration: InputDecoration(
          labelText: AppLocalizations.of(context).bottomBarCampusMap,
        ),
      ),
    );
  }

  Widget _buildSubmitButton() {
    return Expanded(
      child: RaisedButton(
        onPressed: () {},
        child: Icon(Icons.search),
      ),
    );
  }

  Widget _buildForm() {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: 100.0,
      child: Form(
        key: _formKey,
        child: Row(
          children: <Widget>[
            _buildSearchField(),
            _buildSubmitButton(),
          ],
        ),
      ),
    );
  }
}

Вот код GoogleMaps

home: Scaffold(
            body: Stack(
              children: <Widget>[
                _userLocation == null
                    ? Center(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: <Widget>[
                            CircularProgressIndicator(
                              backgroundColor: Theme.UniColour.primary[900],
                            ),
                            SizedBox(height: 20.0),
                            Text("Retrieving your location..."),
                          ],
                        ),
                      )
                    : GoogleMap(
                        onMapCreated: _onMapCreated,
                        initialCameraPosition: // required parameter that sets the starting camera position. Camera position describes which part of the world you want the map to point at.
                            CameraPosition(
                                target: _userLocation,
                                zoom: _defaultZoom,
                                tilt: _tiltAngle), //LatLng(53.467125, -2.233966)
                        scrollGesturesEnabled: _scrollGesturesEnabled,
                        tiltGesturesEnabled: _tiltGesturesEnabled,
                        compassEnabled: _compassEnabled,
                        rotateGesturesEnabled: _rotateGesturesEnabled,
                        myLocationEnabled: _myLocationEnabled,
                        buildingsEnabled: _buildingsEnabled, // not added to db
                        indoorViewEnabled: _indoorViewEnabled, // not added to db
                        mapToolbarEnabled: _mapToolbarEnabled, // not added to db
                        myLocationButtonEnabled:
                            _myLocationButtonEnabled, // not added to db
                        mapType: _currentMapType,
                        zoomGesturesEnabled: _zoomGesturesEnabled,
                        cameraTargetBounds: CameraTargetBounds(
                          new LatLngBounds(
                            northeast: uniCampusNE,
                            southwest: uniCampusSW,
                          ),
                        ),
                        minMaxZoomPreference:
                            MinMaxZoomPreference(_minZoom, _maxZoom),
                      ),
                // Display Building Search feature
                CampusForm(),
              ],
            ),

enter image description here

Любая помощь приветствуется.

спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...