使用Navigator.push(MaterialPageRoute)代替AlertDialog

时间:2019-06-26 14:14:22

标签: flutter dart flutter-layout flutter-appbar

我想使用Navigator.push(MaterialPageRoute)代替AlertDialog,因为现在我认为让用户有一个完整的页面来发布内容而不是对话框是更好的选择,我将如何编辑我的代码来做这个?预先感谢

<ngx-datatable
    #table
    [rows]="rows"
    [messages]="my_messages"
    class="material table"
    [loadingIndicator]="false"
    [columnMode]="'force'"
    [headerHeight]="50"
    [footerHeight]="50"
    style="height: 640px;"
    [rowHeight]="68"
    [scrollbarH]="true"
    [scrollbarV]="true"
    [columns]="columns"
    [limit]="5"
    [loadingIndicator]="isLoading"
    (scroll)="fake($event.offsetY)"
    [selected]="selected"
    [selectionType]="'checkbox'"
    (select)='onSelect($event)'
    (page)="onPageChanged($event)" >

1 个答案:

答案 0 :(得分:0)

创建一个StatefulWidget子类,例如MyForm

class MyForm extends StatefulWidget {
  @override
  _MyFormState createState() => _MyFormState();
}

class _MyFormState extends State<MyForm> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("My form")),
      body: Form(
        key: formKey,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Padding(
              padding: EdgeInsets.all(8.0),
              child: TextFormField(
                initialValue: '',
                onSaved: (val) => board.subject = val,
                validator: (val) => val == "" ? val : null,
              ),
            ),
            Padding(
              padding: EdgeInsets.all(8.0),
              child: RaisedButton(
                color: Colors.indigo,
                child: Text(
                  'Post',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  handleSubmit();
                  Navigator.of(context).pop();
                },
              ),
            )
          ],
        ),
      ),
    );
  }
}

并在您的onPressed方法中像这样使用它。

onPressed: () {
  Navigator.push(context, MaterialPagerRoute(builder: (context) => MyForm()));
}

因此,当单击按钮时,您将导航到当前为表单的新页面。