我想在文本小部件中添加textfield。
这样的:
我想在文本小部件中添加文本字段。
您可以在Row小部件中使用两个单独的Text小部件和一个TextField小部件。这样的:
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: Center(
child: MyStatefulWidget(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
@override
_State createState() => _State();
}
class _State extends State<MyStatefulWidget> {
bool isTextFieldEnabled = true;
@override
Widget build(BuildContext context) {
return Container(
child: Row(
children: [
Text('I want to'),
Container(
width: 200,
child: TextField(
enabled: isTextFieldEnabled,
),
),
Text('textfield in a text widget.'),
],
));
}
}