我使用了一个轻巧的CupertinoScafold,当我使用CupertinoTextFiel并出现键盘时,所有小部件都会调整大小(我使用扩展的小部件)
如果有人可以帮助?
我尝试使用resizeToAvoidBottomInset: false,
,但没有任何改变。也许是因为CupertinoScafold?
这是我的课程:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class GamePage extends StatefulWidget {
@override
_GamePageState createState() => _GamePageState();
}
class _GamePageState extends State<GamePage>{
Color textColor = Color(0xff4e5051);
int totalAnnoncesT1 = 0;
int totalPointsT1 = 0;
List<int> _listAnnonceTeam1 = [1, 1, 1];
List<int> _listPointsTeam1 = [21, 25, 36, 45];
int totalAnnoncesT2 = 0;
int totalPointsT2 = 0;
List<int> _listAnnonceTeam2 = [1, 5, 9];
List<int> _listPointsTeam2 = [21, 25, 45];
ScrollController _controllerAnnonceT1 = new ScrollController();
ScrollController _controllerPointsT1 = new ScrollController();
ScrollController _controllerAnnonceT2 = new ScrollController();
ScrollController _controllerPointsT2 = new ScrollController();
@override
Widget build(BuildContext context){
return CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar(
middle: Text("Jeu", style: TextStyle(fontSize: 20.0),),
),
child: SafeArea(
child: Container(
padding: EdgeInsets.only(left: 15.0, right: 15.0, top: 10.0),
child: Column(
children: <Widget>[
_topInfo(1),
_listInARow(1),
Divider(color: Colors.black,),
_subTotal(1),
Divider(color: Colors.black,),
_total(1),
Divider(color: Colors.black, height: 1, thickness: 2,),
Container(padding: EdgeInsets.symmetric(vertical: 4.0),),
_topInfo(2),
_listInARow(2),
Divider(color: Colors.black,),
_subTotal(2),
Divider(color: Colors.black,),
_total(2),
],
),
),
)
);
}
Widget _listInARow(int numeroTeam) {
if(numeroTeam == 1){
return Expanded(
child: Container(
child: Row(
children: <Widget>[
Expanded(
child: ListView.builder(
controller: _controllerAnnonceT1,
itemCount: _listAnnonceTeam1.length,
itemBuilder: (BuildContext context, int index){
return new Text(_listAnnonceTeam1[index].toString(), textAlign: TextAlign.center, style: TextStyle(color: textColor),);
},
),
),
VerticalDivider(color: Colors.black,),
Expanded(
child: ListView.builder(
controller: _controllerPointsT1,
itemCount: _listPointsTeam1.length,
itemBuilder: (BuildContext context, int index){
return new Text(_listPointsTeam1[index].toString(), textAlign: TextAlign.center, style: TextStyle(color: textColor,));
},
),
),
],
),
),
);
}
else if (numeroTeam == 2){
return Expanded(
child: Container(
child: Row(
children: <Widget>[
Expanded(
child: ListView.builder(
controller: _controllerAnnonceT2,
itemCount: _listAnnonceTeam2.length,
itemBuilder: (BuildContext context, int index){
return new Text(_listAnnonceTeam2[index].toString(), textAlign: TextAlign.center, style: TextStyle(color: textColor),);
},
),
),
VerticalDivider(color: Colors.black,),
Expanded(
child: ListView.builder(
controller: _controllerPointsT2,
itemCount: _listPointsTeam2.length,
itemBuilder: (BuildContext context, int index){
return new Text(_listPointsTeam2[index].toString(), textAlign: TextAlign.center, style: TextStyle(color: textColor,));
},
),
),
],
),
),
);
}
}
Widget _subTotal(int numeroTeam){
totalAnnoncesT1 = 0;
totalPointsT1 = 0;
totalAnnoncesT2 = 0;
totalPointsT2 = 0;
for(int i = 0; i < _listAnnonceTeam1.length; i++){totalAnnoncesT1 += _listAnnonceTeam1[i];}
for(int i = 0; i < _listPointsTeam1.length; i++){totalPointsT1 += _listPointsTeam1[i];}
for(int i = 0; i < _listAnnonceTeam2.length; i++){totalAnnoncesT2 += _listAnnonceTeam2[i];}
for(int i = 0; i < _listPointsTeam2.length; i++){totalPointsT2 += _listPointsTeam2[i];}
print(totalPointsT1);
print(totalAnnoncesT1);
if(numeroTeam == 1){
return Row(
children: <Widget>[
Expanded(child: Container(child: Text(totalAnnoncesT1.toString(), textAlign: TextAlign.center,),), flex: 4,),
Expanded(child: Container(child: Text("Total", textAlign: TextAlign.center,),),),
Expanded(child: Container(child: Text(totalPointsT1.toString(), textAlign: TextAlign.center,),), flex: 4,),
],
);
}
else if (numeroTeam == 2){
return Row(
children: <Widget>[
Expanded(child: Container(child: Text(totalAnnoncesT2.toString(), textAlign: TextAlign.center,),), flex: 4,),
Expanded(child: Container(child: Text("Total", textAlign: TextAlign.center,),),),
Expanded(child: Container(child: Text(totalPointsT2.toString(), textAlign: TextAlign.center,),), flex: 4,),
],
);
}
}
Widget _total(int numeroTeam){
if (numeroTeam == 1) {
return Row(
children: <Widget>[
Text("Total :"),
Expanded(
child: Container(
child: Text((totalPointsT1 + totalAnnoncesT1).toString(), textAlign: TextAlign.center,),
),
),
CupertinoButton(
padding: EdgeInsets.only(top:0, bottom: 0, left: 0, right: 0),
child: Text("+", style: TextStyle(fontSize: 25),),
onPressed: () => print(""),
)
],
);
}
else if (numeroTeam == 2){
return Row(
children: <Widget>[
Text("Total :"),
Expanded(
child: Container(
child: Text((totalPointsT2 + totalAnnoncesT2).toString(), textAlign: TextAlign.center,),
),
),
CupertinoButton(
padding: EdgeInsets.only(top:0, bottom: 0, left: 0, right: 0),
child: Text("+", style: TextStyle(fontSize: 25),),
onPressed: () => print(""),
)
],
);
}
}
Widget _topInfo(int teamNumber){
return Column(
children: <Widget>[
CupertinoTextField(
placeholder: "Team " + teamNumber.toString(),
textAlign: TextAlign.center,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
),
),
Container(padding: EdgeInsets.all(5.0),),
Row(
children: <Widget>[
Expanded(child: Container(child: Text("Annonces :", textAlign: TextAlign.center,),),),
Expanded(child: Container(child: Text("Points réguliers :", textAlign: TextAlign.center,),),),
],
),
],
);
}
}
感谢您的回答!