我有以下小部件
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Playground',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.green,
body: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 100,
color: Colors.black,
child: const ResponsiveInput(),
),
),
);
}
}
class ResponsiveInput extends StatelessWidget {
const ResponsiveInput({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: TextFormField(
decoration: const InputDecoration(
fillColor: Colors.white,
filled: true,
),
),
),
TextButton(
onPressed: () => false,
child: const Text('Send'),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.orange)),
)
],
);
}
}
執行以下操作
[![在此處輸入影像描述][1]][1]
但是如何讓文本欄位填充黑色容器中的剩余空間?
我嘗試使用內容填充,但結果是如果容器具有回應高度,則文本將被截斷。即使使用密集。
uj5u.com熱心網友回復:
您可以使用expands: true, maxLines: null,上TextFormField
擴張如果設定為true,并包裹在一個父部件像膨化或SizedBox,輸入將擴大,以填補父。
Expanded(
child: TextFormField(
expands: true,
maxLines: null,
decoration: const InputDecoration(
fillColor: Colors.white,
filled: true,
),
),
),
更多關于擴展
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/391675.html
