InputDecoratorは通常TextFieldによって作成されますが、無制限の幅を持つことはできません。質問する

InputDecoratorは通常TextFieldによって作成されますが、無制限の幅を持つことはできません。質問する

このエラーをどうやって解消するか分からない(通常 TextField によって作成される InputDecorator は、無制限の幅を持つことはできません。) だけでなく、 2 つの内部テキストフィールドが列の幅全体を占めるようにします。

Column(mainAxisSize: MainAxisSize.min, children: [
                      Container(
                        margin: const EdgeInsets.only(left: 50, right: 50),
                        child: AutoCompleteTextView(
                          suggestionsApiFetchDelay: 300,
                          focusGained: () {},
                          onTapCallback: (_) async {

                          },
                          focusLost: () {

                          },
                          onValueChanged: (String text) {

                          },
                          controller: startEditingController,
                          suggestionStyle:
                              Theme.of(context).textTheme.bodyText2,
                          getSuggestionsMethod: getLocationSuggestionsList,
                          tfTextAlign: TextAlign.left,
                          tfStyle: TextStyle(
                            fontSize: 16,
                            color: Theme.of(context).textTheme.bodyText2.color,
                          ),
                          tfTextDecoration: InputDecoration(
                            contentPadding: EdgeInsets.only(top: 0, left: 8.0),
                            filled: true,
                            fillColor: Colors.white,
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                  color: Colors.grey[800], width: 1.0),
                              borderRadius: BorderRadius.zero,
                            ),
                            enabledBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                  color: Colors.deepPurple[600], width: 1.0),
                              borderRadius: BorderRadius.zero,
                            ),
                            hintText: "Current Location",
                            labelText: 'Start',
                            labelStyle: kcarPurpleLabelStyle,
                          ),
                        ),
                      ),
                      Container(
                        margin:
                            const EdgeInsets.only(top: 5, left: 50, right: 50),
                        child: AutoCompleteTextView(
                          suggestionsApiFetchDelay: 300,
                          focusGained: () {},
                          onTapCallback: (_) async {

                          },
                          focusLost: () {

                          },
                          onValueChanged: (String text) {

                          },
                          controller: startEditingController,
                          suggestionStyle:
                              Theme.of(context).textTheme.bodyText2,
                          getSuggestionsMethod: getLocationSuggestionsList,
                          tfTextAlign: TextAlign.left,
                          tfStyle: TextStyle(
                            fontSize: 16,
                            color: Theme.of(context).textTheme.bodyText2.color,
                          ),
                          tfTextDecoration: InputDecoration(
                            contentPadding: EdgeInsets.only(top: 0, left: 8.0),
                            filled: true,
                            fillColor: Colors.white,
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                  color: Colors.grey[800], width: 1.0),
                              borderRadius: BorderRadius.zero,
                            ),
                            enabledBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                  color: Colors.deepPurple[600], width: 1.0),
                              borderRadius: BorderRadius.zero,
                            ),
                            hintText: "Current Location",
                            labelText: 'Destination',
                            labelStyle: kcarPurpleLabelStyle,
                          ),
                        ),
                      )
                    ]),

ベストアンサー1

列はそのままにして、各テキストフィールドを拡大ウィジェット。理由は公式ドキュメントに記載されています。

行、列、またはフレックスの子要素を拡張して、使用可能なスペースを埋めるウィジェット。

Expanded ウィジェットを使用すると、行、列、または Flex の子が、主軸に沿って使用可能なスペースを埋めるように拡張されます (たとえば、行の場合は水平方向、列の場合は垂直方向)。複数の子が拡張されている場合、使用可能なスペースは flex 係数に従ってそれらの間で分割されます。

ソース:拡張クラス

おすすめ記事