我在网格视图顶部获得了一个空间。我尝试将其删除但没有成功。它看起来像这样:
我想要的是:
这是我的代码:
Container(
margin: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Check",
style: TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.bold),
textAlign: TextAlign.left,
),
GridView.count(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 1,
crossAxisSpacing: 2,
mainAxisSpacing: 10,
childAspectRatio: 5.1,
children: <Widget>[
GestureDetector(
child: _buildWidget("Car", 0),
onTap: () => setState(() => _languageIndex = 0),
),
GestureDetector(
child: _buildWidget("Boat", 1),
onTap: () => setState(() => _languageIndex = 1),
),
],
),
],
));
Widget _buildWidget(String language, int index) {
bool isSelected = _languageIndex == …Run Code Online (Sandbox Code Playgroud) 我有3个不同的功能,我想随机调用其中一个.
if Int(ball.position.y) > maxIndexY! {
let randomFunc = [self.firstFunction(), self.secondFunction(), self.thirdFunction()]
let randomResult = Int(arc4random_uniform(UInt32(randomFunc.count)))
return randomFunc[randomResult]
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,我调用所有函数,顺序始终相同.我可以做些什么来打电话给其中一个?
我试图从一个页面导航到另一个页面并设置标签栏的索引。
这是我在第一页的代码:
GestureDetector(
onTap: () { Navigator.push(
context,
MaterialPageRoute(builder: (context) => ProductPage()),
); },
child: Container(
color: Colors.blueGrey,
)),
Run Code Online (Sandbox Code Playgroud)
在另一个页面(ProductPage)中:
class ProductPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
backgroundColor: Color.fromRGBO(65,102,60,1,
),
bottom: TabBar(
isScrollable: true,
indicatorColor: Colors.white,
tabs: [
Tab(icon: Text('First')),
Tab(icon: Text('Second')),
Tab(icon: Text('Third')),
],
),
),
body: TabBarView(
children: [
FirstTab(),
SecondTab(),
ThirdTab(),
],
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
现在它总是打开第一个选项卡,但我希望它打开 SecondTab。
我试过这个:
MaterialPageRoute(builder: (context) => ProductPage(SecondTab)),
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我该怎么做才能解决这个问题?