在创建团队后,我正在开发一个计算积分的应用程序。创建团队后,会弹出一个 AlertDialog 并显示名称。然后应该可以点击一个按钮来打开一个新的活动。该活动不应与之前的活动相关联。有没有人有想法,如何做到这一点?
这是对话框活动的代码片段:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
如果有人有想法,那就太棒了:D
实际上,当您谈论 Flutter 时,请考虑页面,而不是活动。它应该是这样的:
Navigator.push(context,
MaterialPageRoute(builder: (context) => SecondScreen()),);
Run Code Online (Sandbox Code Playgroud)
SecondScreen 是另一个具有自己的 Widget build(BuildContext context) 方法的小部件,您将在该方法中声明此页面上的内容。
如果你想回来,你可以这样做:
Navigator.pop(context);
Run Code Online (Sandbox Code Playgroud)
源文件
您还可以使用命名路线进行导航。例子:
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(),
},
);
Run Code Online (Sandbox Code Playgroud)
和类似的东西:
Navigator.pushNamed(context, '/second');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4788 次 |
| 最近记录: |