Flutter 如何更改单选按钮列表的视觉效果?
我有一个打赌游戏,它是一个游戏列表,用户需要在3个选项(只有一个选项)(1,N,2)中进行选择,所以我在flutter中使用了radio 1-以下是我现在得到的结果: 2-以下是我想要的结果: 我需要有相同的收音机1 N 2,而不使用任何图像,我认为可以使用clipoval,也许是圆形边框。此处所选收音机背景为红色,因此当我单击另一台收音机时,它需要更改收音机的颜色(如果选中,则为红色背景和白色字体,如果未选中,则为白色背景和红色字体) 下面是我的整个网格代码:Flutter 如何更改单选按钮列表的视觉效果?,flutter,Flutter,我有一个打赌游戏,它是一个游戏列表,用户需要在3个选项(只有一个选项)(1,N,2)中进行选择,所以我在flutter中使用了radio 1-以下是我现在得到的结果: 2-以下是我想要的结果: 我需要有相同的收音机1 N 2,而不使用任何图像,我认为可以使用clipoval,也许是圆形边框。此处所选收音机背景为红色,因此当我单击另一台收音机时,它需要更改收音机的颜色(如果选中,则为红色背景和白色字体,如果未选中,则为白色背景和红色字体) 下面是我的整个网格代码: import 'packag
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'package:flutter_app/menu_member.dart';
import 'package:flutter_app/globals.dart' as globals;
import 'package:flutter_app/grille_lotosport.dart';
// Create
a Form widget.
class Affiche_grille extends StatefulWidget {
@override
String id;
Affiche_grille({Key key, @required this.id}) : super(key: key);
_Affiche_grille_State createState() {
return _Affiche_grille_State();
}
}
// Create a corresponding State class.
// This class holds data related to the form.
class _Affiche_grille_State extends State<Affiche_grille> {
@override
final _formKey = GlobalKey<FormState>();
List<String> radioValues = [];
Future<List<Match>> grid;
Future <List<Match>> Grille_display() async {
// SERVER LOGIN API URL
var url = 'https://www.easytrafic.fr/game_app/display_grid.php';
// Store all data with Param Name.
var data = {'id_grille': widget.id};
// Starting Web API Call.
var response = await http.post(url, body: json.encode(data),headers: {'content-type': 'application/json','accept': 'application/json','authorization': globals.token});
// Getting Server response into variable.
var jsondata = json.decode(response.body);
List<Match> Matchs = [];
for (var u in jsondata) {
Match match = Match(u["equipe1"],u["equipe2"],u["type_prono"]);
Matchs.add(match);
radioValues.add("N");
}
return Matchs;
}
void initState() {
grid = Grille_display();
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('GRILLE LOTOSPORT'),
),
drawer: new DrawerOnly(),
body:
Container(
child:
FutureBuilder(
future: grid,
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return new Center(
child: new CircularProgressIndicator(),);
default:
if (snapshot.hasError) {
return new Center(
child: new Text('Error: ${snapshot.error}'),);
}
else {
List<Match> values = snapshot.data;
return Form(
key: _formKey,
child: ListView(
children: <Widget>[
DataTable(
columnSpacing: 20,
columns: [
DataColumn(
label: Text("Libelle Match"),
numeric: false,
tooltip: "",
),
DataColumn(
label: Text("1"),
numeric: false,
tooltip: "",
),
DataColumn(
label: Text("N"),
numeric: false,
tooltip: "",
),
DataColumn(
label: Text("2"),
numeric: false,
tooltip: "",
),
],
rows:
List.generate(values.length, (index) {
return DataRow(
cells: [
DataCell(
Text(values[index].equipe1.toString() +
" - " +
values[index].equipe2.toString()),
),
DataCell(
Radio(
value: "1",
groupValue: radioValues[index],
onChanged: (val) {
setState(() {
radioValues[index] = val;
});
},
),
),
DataCell(
Radio(
value: "N",
groupValue: radioValues[index],
onChanged: (val) {
setState(() {
radioValues[index] = val;
});
},
),
),
DataCell(
Radio(
value: "2",
groupValue: radioValues[index],
onChanged: (val) {
setState(() {
radioValues[index] = val;
});
},
),
),
]
);
}).toList(),
),
Center(
child: RaisedButton(
color: Colors.green,
textColor: Colors.white,
padding: EdgeInsets.fromLTRB(9, 9, 9, 9),
child: Text('VALIDER VOTRE GRILLE'),
onPressed: () {
Valide_grille();
},
),
),
],
)
);
};
};
},
),
),
),
);
}
Future Valide_grille() async{
// For CircularProgressIndicator.
bool visible = false ;
// Showing CircularProgressIndicator.
setState(() {
visible = true ;
});
// SERVER LOGIN API URL
var url = 'https://www.easytrafic.fr/game_app/valide_grid.php';
var concatenate='';
radioValues.forEach((item){
concatenate=concatenate+item;
});
var id_grille=widget.id;
// Store all data with Param Name.
var data = {'id_membre':globals.id_membre, 'id_grille':id_grille,'result':concatenate};
var grille_encode=jsonEncode(data);
// Starting Web API Call.
var response = await http.post(url, body: grille_encode,headers: {'content-type': 'application/json','accept': 'application/json','authorization': globals.token});
print(response.body);
// Getting Server response into variable.
Map <String,dynamic> map2 = json.decode(response.body);
// If the Response Message is Matched.
if(map2["status"] == 1)
{
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text(map2["message"]),
actions: <Widget>[
FlatButton(
child: new Text("OK"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Affiche_Liste_grille()),
);
},
),
],
);
},
);
// Hiding the CircularProgressIndicator.
setState(() {
visible = false;
});
}else{
// Hiding the CircularProgressIndicator.
setState(() {
visible = false;
});
// Showing Alert Dialog with Response JSON Message.
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text(map2["message"]),
actions: <Widget>[
FlatButton(
child: new Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
}
class Match {
final String equipe1;
final String equipe2;
final String typeprono;
const Match(this.equipe1, this.equipe2, this.typeprono);
}
导入“包装:颤振/材料.省道”;
导入“dart:convert”;
将“package:http/http.dart”导入为http;
导入“dart:async”;
导入“包:颤振应用程序/菜单成员.dart”;
将“package:flatter_app/globals.dart”导入为globals;
进口“包装:颤振应用程序/格栅”lotosport.dart”;
//创造
表单小部件。
类Affiche\u扩展StatefulWidget{
@凌驾
字符串id;
Affiche_格栅({Key Key,@required this.id}):super(Key:Key);
_粘贴格栅状态createState(){
返回_Affiche_grill_State();
}
}
//创建相应的状态类。
//此类保存与表单相关的数据。
类(粘贴)(格栅)(状态)扩展状态{
@凌驾
final _formKey=GlobalKey();
列出radioValues=[];
未来电网;
Future grillu display()异步{
//服务器登录API URL
var url='1〕https://www.easytrafic.fr/game_app/display_grid.php';
//使用参数名称存储所有数据。
var data={'id\u':widget.id};
//正在启动Web API调用。
var response=wait http.post(url,主体:json.encode(数据),标题:{'content-type':'application/json','accept':'application/json','authorization':globals.token});
//正在将服务器响应转换为变量。
var jsondata=json.decode(response.body);
列表匹配=[];
用于(jsondata中的变量u){
匹配匹配=匹配(u[“equipe1”]、u[“equipe2”]、u[“type_prono”]);
匹配。添加(匹配);
radioValues.添加(“N”);
}
返回匹配;
}
void initState(){
网格=网格显示();
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
appBar:appBar(标题:Text('ground LOTOSPORT'),
),
抽屉:新抽屉(),
正文:
容器(
儿童:
未来建设者(
未来:网格,
生成器:(BuildContext上下文,异步快照){
交换机(快照.连接状态){
案例连接状态。正在等待:
返回新中心(
子项:新循环ProgressIndicator(),);
违约:
if(snapshot.hasError){
返回新中心(
子项:新文本('Error:${snapshot.Error}');
}
否则{
列表值=snapshot.data;
报税表(
键:_formKey,
子:ListView(
儿童:[
数据表(
柱间距:20,
栏目:[
数据列(
标签:文本(“诽谤匹配”),
数字:false,
工具提示:“”,
),
数据列(
标签:文本(“1”),
数字:false,
工具提示:“”,
),
数据列(
标签:文本(“N”),
数字:false,
工具提示:“”,
),
数据列(
标签:文本(“2”),
数字:false,
工具提示:“”,
),
],
排:
List.generate(values.length,(index){
返回数据行(
单元格:[
数据单元(
文本(值[index].equipe1.toString()+
" - " +
值[index].equipe2.toString()),
),
数据单元(
无线电(
值:“1”,
groupValue:radioValues[索引],
一旦更改:(val){
设置状态(){
放射性值[指数]=val;
});
},
),
),
数据单元(
无线电(
值:“N”,
groupValue:radioValues[索引],
一旦更改:(val){
设置状态(){
放射性值[指数]=val;
});