Not getting output using flutter.

huangapple go评论58阅读模式
英文:

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布局存在一些问题。您可以检查以下方面:

  1. 确保您的UI布局正确嵌套,以使姓名和性别字段在屏幕上显示。

  2. 检查您的文本字段和RadioListTile是否被正确添加到UI层次结构中。

  3. 确保没有其他的错误或警告在运行时出现,可能会影响UI渲染。

如果您需要更具体的帮助,请提供更多关于问题的信息,以便我能够提供更详细的建议。

英文:

I am writing code to generate user form using Flutter. Following is my code.

import &#39;package:flutter/material.dart&#39;;

void main() =&gt; 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(&#39;User Profile&#39;)),
        body: const RadioListTileExample(),
      ),
    );
  }
}

enum SingingCharacter {Male, Female}


class RadioListTileExample extends StatefulWidget {
  const RadioListTileExample({super.key});

  @override
  State&lt;RadioListTileExample&gt; createState() =&gt; _RadioListTileExampleState();
}

class _RadioListTileExampleState extends State&lt;RadioListTileExample&gt; {
  SingingCharacter? _character = SingingCharacter.Male;
  

  @override
  Widget build(BuildContext context) {
    return Column(
      children: &lt;Widget&gt;[
        ListView( 
                    Container( 
          child: TextField(
            decoration: InputDecoration(
              border: UnderlineInputBorder(),
              hintText: &#39;Name&#39;,
            ),
          ),
        ),

        Container(
        Text(&quot;Gender&quot;),
        RadioListTile&lt;SingingCharacter&gt;(
          title: const Text(&#39;Male&#39;),
          value: SingingCharacter.Male,
          groupValue: _character,
          onChanged: (SingingCharacter? value) {
            setState(() {
              _character = value;
            });
          },
        ),
        RadioListTile&lt;SingingCharacter&gt;(
          title: const Text(&#39;Female&#39;),
          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 &#39;package:flutter/material.dart&#39;;

void main() =&gt; 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(&#39;User Profile&#39;)),
        body: const RadioListTileExample(),
      ),
    );
  }
}

enum SingingCharacter { Male, Female }

class RadioListTileExample extends StatefulWidget {
  const RadioListTileExample({super.key});

  @override
  State&lt;RadioListTileExample&gt; createState() =&gt; _RadioListTileExampleState();
}

class _RadioListTileExampleState extends State&lt;RadioListTileExample&gt; {
  SingingCharacter? _character = SingingCharacter.Male;

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(children: &lt;Widget&gt;[
        TextField(
          decoration: InputDecoration(
            border: UnderlineInputBorder(),
            hintText: &#39;Name&#39;,
          ),
        ),
        Text(&quot;Gender&quot;),
        RadioListTile&lt;SingingCharacter&gt;(
          title: const Text(&#39;Male&#39;),
          value: SingingCharacter.Male,
          groupValue: _character,
          onChanged: (SingingCharacter? value) {
            setState(() {
              _character = value;
            });
          },
        ),
        RadioListTile&lt;SingingCharacter&gt;(
          title: const Text(&#39;Female&#39;),
          value: SingingCharacter.Female,
          groupValue: _character,
          onChanged: (SingingCharacter? value) {
            setState(() {
              _character = value;
            });
          },
        ),
      ]),
    );
  }
}

huangapple
  • 本文由 发表于 2023年5月17日 20:23:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76272069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定