英文:
Not getting output using flutter
问题
以下是您的代码的翻译:
我正在编写代码,使用Flutter生成用户表单。以下是我的代码。
import 'package:flutter/material.dart';
void main() => runApp(const RadioListTileApp());
class RadioListTileApp extends StatelessWidget {
const RadioListTileApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('用户资料')),
body: const RadioListTileExample(),
),
);
}
}
enum SingingCharacter { 男, 女 }
class RadioListTileExample extends StatefulWidget {
const RadioListTileExample({super.key});
@override
State<RadioListTileExample> createState() => _RadioListTileExampleState();
}
class _RadioListTileExampleState extends State<RadioListTileExample> {
SingingCharacter? _character = SingingCharacter.男;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
ListView(
children: <Widget>[
Container(
child: TextField(
decoration: InputDecoration(
border: UnderlineInputBorder(),
hintText: '姓名',
),
),
),
Container(
Text("性别"),
RadioListTile<SingingCharacter>(
title: const Text('男'),
value: SingingCharacter.男,
groupValue: _character,
onChanged: (SingingCharacter? value) {
setState(() {
_character = value;
});
},
),
RadioListTile<SingingCharacter>(
title: const Text('女'),
value: SingingCharacter.女,
groupValue: _character,
onChanged: (SingingCharacter? value) {
setState(() {
_character = value;
});
},
),
),
],
),
],
);
}
}
关于您的问题,您在输出屏幕上只能看到“用户资料”文本,而“姓名”和“性别”等字段丢失的问题,可能是因为您的UI布局存在一些问题。您可以检查以下方面:
-
确保您的UI布局正确嵌套,以使姓名和性别字段在屏幕上显示。
-
检查您的文本字段和RadioListTile是否被正确添加到UI层次结构中。
-
确保没有其他的错误或警告在运行时出现,可能会影响UI渲染。
如果您需要更具体的帮助,请提供更多关于问题的信息,以便我能够提供更详细的建议。
英文:
I am writing code to generate user form using Flutter. Following is my code.
import 'package:flutter/material.dart';
void main() => runApp(const RadioListTileApp());
class RadioListTileApp extends StatelessWidget {
const RadioListTileApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('User Profile')),
body: const RadioListTileExample(),
),
);
}
}
enum SingingCharacter {Male, Female}
class RadioListTileExample extends StatefulWidget {
const RadioListTileExample({super.key});
@override
State<RadioListTileExample> createState() => _RadioListTileExampleState();
}
class _RadioListTileExampleState extends State<RadioListTileExample> {
SingingCharacter? _character = SingingCharacter.Male;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
ListView(
Container(
child: TextField(
decoration: InputDecoration(
border: UnderlineInputBorder(),
hintText: 'Name',
),
),
),
Container(
Text("Gender"),
RadioListTile<SingingCharacter>(
title: const Text('Male'),
value: SingingCharacter.Male,
groupValue: _character,
onChanged: (SingingCharacter? value) {
setState(() {
_character = value;
});
},
),
RadioListTile<SingingCharacter>(
title: const Text('Female'),
value: SingingCharacter.Female,
groupValue: _character,
onChanged: (SingingCharacter? value) {
setState(() {
_character = value;
});
},
),
),
),
],
);
}
}
What is wrong with my code?
On my output screen, I am able to see only "User Profile" text. Fields such as "Name" and "Gender" are missing.
答案1
得分: 0
以下是您要翻译的部分:
"Well i don't know how your code run successfully as i am able to see many things missing like child
key in ListView
and Container
and also many childs are written within Container
with Column
and also don't need to use ListView
to make your screen scrollable for form. You can use SingleChildScrollView
. Try with below mentioned code
import 'package:flutter/material.dart';
void main() => runApp(const RadioListTileApp());
class RadioListTileApp extends StatelessWidget {
const RadioListTileApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('User Profile')),
body: const RadioListTileExample(),
),
);
}
}
enum SingingCharacter { Male, Female }
class RadioListTileExample extends StatefulWidget {
const RadioListTileExample({super.key});
@override
State<RadioListTileExample> createState() => _RadioListTileExampleState();
}
class _RadioListTileExampleState extends State<RadioListTileExample> {
SingingCharacter? _character = SingingCharacter.Male;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(children: <Widget>[
TextField(
decoration: InputDecoration(
border: UnderlineInputBorder(),
hintText: 'Name',
),
),
Text("Gender"),
RadioListTile<SingingCharacter>(
title: const Text('Male'),
value: SingingCharacter.Male,
groupValue: _character,
onChanged: (SingingCharacter? value) {
setState(() {
_character = value;
});
},
),
RadioListTile<SingingCharacter>(
title: const Text('Female'),
value: SingingCharacter.Female,
groupValue: _character,
onChanged: (SingingCharacter? value) {
setState(() {
_character = value;
});
},
),
]),
);
}
}
英文:
Well i don't know how your code run successfully as i am able to see many things missing like child
key in ListView
and Container
and also many childs are written within Container
with Column
and also don't need to use ListView
to make your screen scrollable for form . You can use SingleChildViewScroll
. Try with below mention code
import 'package:flutter/material.dart';
void main() => runApp(const RadioListTileApp());
class RadioListTileApp extends StatelessWidget {
const RadioListTileApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('User Profile')),
body: const RadioListTileExample(),
),
);
}
}
enum SingingCharacter { Male, Female }
class RadioListTileExample extends StatefulWidget {
const RadioListTileExample({super.key});
@override
State<RadioListTileExample> createState() => _RadioListTileExampleState();
}
class _RadioListTileExampleState extends State<RadioListTileExample> {
SingingCharacter? _character = SingingCharacter.Male;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(children: <Widget>[
TextField(
decoration: InputDecoration(
border: UnderlineInputBorder(),
hintText: 'Name',
),
),
Text("Gender"),
RadioListTile<SingingCharacter>(
title: const Text('Male'),
value: SingingCharacter.Male,
groupValue: _character,
onChanged: (SingingCharacter? value) {
setState(() {
_character = value;
});
},
),
RadioListTile<SingingCharacter>(
title: const Text('Female'),
value: SingingCharacter.Female,
groupValue: _character,
onChanged: (SingingCharacter? value) {
setState(() {
_character = value;
});
},
),
]),
);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论