English 中文(简体)
形成多页的冲破
原标题:Making a multi page form in flutter

因此,我想提出一个多页表格,上面有一条线性进展指标,而不是通常的双向目标,我对许多不同的SO网站进行了尝试,而任何网站都没有发挥作用,我都需要一切,

我想的是:

  • to have a different page for each step
  • a way to return the data collected from each step
  • a bar at the top to show how close you are to finishing the form
  • and a way to edit each page serperately

对我如何这样做的任何建议都会如此赞赏,并事先感谢你。

问题回答

首先,它为你的问题提供了简短的解决办法(最简单的解决办法)。

the below code should be refactored and and can be enhanced, but i m presenting an idea. here s the code, the coming is the driver class that manages the Linear Progress Indicator(LPI) and page view.

class HomeScreen extends StatefulWidget {
   HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  var pages =  [ FirstPage(),SecondPage(), ThirdPage(),FourthPage(),];

  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    print( called );
    return SafeArea(
      child: Scaffold(
        body: Column(
          children: [
             Padding(
               padding: EdgeInsets.symmetric(horizontal: 10,vertical: 30),
               child: LinearProgressIndicator(
                 color: Colors.blue.shade700,
                 value: (currentIndex+1) /4,
                 borderRadius: BorderRadius.circular(10),
                 minHeight: 20,
               ),
             ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.all(15),
                child: PageView(
                  children: pages,
                  onPageChanged: (i){
                    setState(() {
                      currentIndex = i;
                    });
                  },
                  padEnds: true,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

ok,页数变量是植被清单,每个植被在每一页都有所表述的内容。

FirstPage。 植被执行

class FirstPage extends StatelessWidget {

  static var controller = TextEditingController();
  const FirstPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text( First Page ),
        ),
        TextFormField(
          controller: controller,
          decoration: InputDecoration(
              label: Text( Name ),
            enabledBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(8),
              borderSide: BorderSide(width: 1,color: Colors.blue)
            )
          ),
        ),
      ],
    );
  }
}

页: 1 第三页的执行与另一页相同。

class SecondPage extends StatelessWidget {
  static var controller = TextEditingController();
  const SecondPage({super.key});


  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text( Second Page ),
        ),
        TextFormField(
          controller: controller,
          decoration: InputDecoration(
            label: Text( phone ),
              enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(8),
                  borderSide: BorderSide(width: 1,color: Colors.blue)
              )
          ),
        ),
      ],
    );
  }
}

如果你注意到每一页(级)的文字领域都有控制者,使我们能够最后获得书面文本。

最后一页

class FourthPage extends StatelessWidget {
  static var controller = TextEditingController();
  const FourthPage({super.key});


  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text( Fourth Page ),
        ),
        TextFormField(
          controller: controller,
          onFieldSubmitted: (s){
            Navigator.of(context).push(
                MaterialPageRoute(
                    builder: (context)=> FinalScreen(),
                    settings: RouteSettings(
                      arguments: {
                         first  : FirstPage.controller.text,
                         second  : SecondPage.controller.text,
                         third  : ThirdPage.controller.text,
                         fourth  : FourthPage.controller.text
                      },
                    )
                )
            );
          },
          decoration: InputDecoration(
              label: Text( Password ),
              enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(8),
                  borderSide: BorderSide(width: 1,color: Colors.blue)
              )
          ),
        ),
      ],
    );
  }
}

第四页和最后一页有一条关键的编码线,在用户向文字领域提交价值时予以执行(在家庭或最后一页上浏览,并使用线路环境向该网页发送数据)。

用户收集数据的最后一页

class FinalScreen extends StatelessWidget {
  const FinalScreen({super.key});

  @override
  Widget build(BuildContext context) {

    var data = ModalRoute.of(context)?.settings.arguments as Map<String,String>;

    return Scaffold(
      appBar: AppBar(
        title: Text( Final Screen ),
        centerTitle: true,
      ),
      body: Container(
        width: double.infinity,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text( first page data: ${data[ first ]} ),
            Text( second page data: ${data[ second ]} ),
            Text( third page data: ${data[ third ]} ),
            Text( fourth page data: ${data[ fourth ]} ),
          ],
        ),
      ),
    );
  }
}

notice: the above code doesn t make text input validation, you should do (wrap them with form you know) and validate user input on each page view swipe. if the input violates your rules swipe back to the previous page and alert the user (use page view controller).

这里的产出

“entergraph





相关问题
How to start to create an application GUI using C#?

HI! I am new to C# and plan to use it for my application GUI. I am trying to make my GUI similar to SPSS:http://www.spss.com/images/08/statistics_screens/ez_rfm-big.jpg Is this easy in C#? Is there ...

Automatic height of edit box

My shoes application has three items stacked on top of each other (with a stack, of course), in order: A banner An edit box Two buttons in a flow What I want to do is have the banner stay at it s ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

UI And TcpClient Issue in vb.net

I m having some problems with a small ircbot i m writing. Basically I connect to the server using a tcpclient in a seperate class, which also runs on its own thread. I want to display the server text ...

UI Convention: Shortcut key for application exit? [closed]

Is there a convention for the shortcut keys for application exit? Some applications uses Alt+X some others use Ctrl+ X and Ctrl+Q. Applications like FF and IE doesnot assign a shortcut at all. So is ...