创建团队后,我正在开发一个计算点数的应用程序。创建团队后,将弹出AlertDialog并显示名称。然后应该可以单击一个按钮以打开新 Activity 。该 Activity 不应与上一个 Activity 相关联。是否有人有想法,如何实现?

这是对话框 Activity 的代码片段:

import 'dart:math';
import 'package:flutter/material.dart';

import 'punktezaehler.dart';

class Team_Dialog extends StatefulWidget{

  final List<String> team_namen;

  Team_Dialog(this.team_namen);

  @override
  State<StatefulWidget> createState() => new _TeamDialogState(team_namen);

}

class _TeamDialogState extends State<Team_Dialog>{

  final List<String> team_namen;
  _TeamDialogState(this.team_namen);

  @override
  Widget build(BuildContext context) {
    return new AlertDialog(
      content: new SingleChildScrollView(
        child: new ListBody(
            children: List.generate(1, (index){
              return Column(
                children: <Widget>[
                  new Row(
                    children: <Widget>[
                      Text("Team 1: ", style: TextStyle(fontFamily: "Roboto")),
                      Text(team_namen[0] + " und " + team_namen[1])
                    ],
                  ),
                  new Row(
                    children: <Widget>[
                      Text("Team 2: "),
                      Text(team_namen[2] + " und " + team_namen[3])
                    ],
                  )
                ],
              );
            })
        ),
      ),
      actions: <Widget>[
        new FlatButton(
            color: Colors.red,
            splashColor: Colors.red[900],
            onPressed: (){
              Navigator.of(context).pop();
            },
            child: new Text("Abort", style: TextStyle(color: Colors.white),)
        ),
        new IconButton(
            icon: Icon(Icons.shuffle),
            onPressed: (){
              shuffle(team_namen);
              setState(() {
              });
            }
        ),
        new FlatButton(
            color: Colors.green,
            splashColor: Colors.green[800],
            onPressed: () => , //After click it should start new Activity
            child: new Text("Start Game", style: TextStyle(color:  Colors.white))
        )
      ],
    );
  }



  List shuffle(List items) {
    var random = new Random();

    for (var i = items.length - 1; i > 0; i--) {

      var n = random.nextInt(i + 1);

      var temp = items[i];
      items[i] = items[n];
      items[n] = temp;
    }

    return items;
  }


}

如果有人有一个主意,那将是很棒的:D

最佳答案

实际上,当您谈论Flutter时,请考虑页面而不是 Activity 。应该是这样的:

Navigator.push(context,
   MaterialPageRoute(builder: (context) => SecondScreen()),);

SecondScreen是另一个具有自己的Widget build(BuildContext context)方法的小部件,您可以在其中声明此页面上的内容。

如果您想返回,可以使用以下方法:
 Navigator.pop(context);

来源documentation

您也可以使用命名路线进行导航。例:
MaterialApp(
  // Start the app with the "/" named route. In our case, the app will start
  // on the FirstScreen Widget
  initialRoute: '/',
  routes: {
    // When we navigate to the "/" route, build the FirstScreen Widget
    '/': (context) => FirstScreen(),
    // When we navigate to the "/second" route, build the SecondScreen Widget
    '/second': (context) => SecondScreen(),
  },
);

和类似的东西:
Navigator.pushNamed(context, '/second');

Documentation

10-06 13:18
查看更多