gpt4 book ai didi

flutter - 交错 GridView Flutter onTap 不适用于我的代码中的 tile

转载 作者:行者123 更新时间:2023-12-04 09:38:49 30 4
gpt4 key购买 nike

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:landregapp/HomePage.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:landregapp/TypeofLands.dart';


void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "landRegistration App",
theme: new ThemeData(primarySwatch: Colors.amber),
home: landReg(),
);
}
}

class landReg extends StatefulWidget {
@override
_landRegState createState() => _landRegState();
}

class _landRegState extends State<landReg> {
Material myItems(IconData icon, String heading )
{
return Material(
color: Colors.amber,
elevation: 14.0,
borderRadius: BorderRadius.circular(24.0),
child:Center(
child:Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(1.0),
child: Icon(
icon,
),
),

Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
heading,
style: TextStyle(
fontWeight: FontWeight.w700,
),
),
),


],
)
],
),
)
)
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text("Home page"),
elevation: 5.0,
),

drawer: new Drawer(
child: new ListView(
children: <Widget>[

new UserAccountsDrawerHeader(

accountName: new Text("MLHUD"),
accountEmail: new Text("dennisfo@mlhud.go.ug"),
currentAccountPicture: new CircleAvatar(
radius: 90.0,
backgroundImage: AssetImage('asset/image/uganda.jpg'),
backgroundColor: Colors.transparent,
),
),
new ListTile(
leading: Icon(Icons.home),
title: new Text("Home"),
),
new ListTile(
leading: Icon(Icons.assignment),
title: new Text("Terms and Conditions"),

),
new ListTile(
leading: Icon(Icons.info),
title: new Text("About App"),

),

new ListTile(
leading: Icon(Icons.phone),
title: new Text("Contact Us"),
),

new ListTile(
leading: Icon(Icons.share),
title: new Text("Share"),
),

new ListTile(
leading: Icon(Icons.exit_to_app),
title: new Text("Exit"),
),
],
),
),

body:StaggeredGridView.count(
crossAxisCount: 2,
crossAxisSpacing: 12.0,
mainAxisSpacing: 12.0,

padding: EdgeInsets.symmetric(horizontal: 10.0,vertical: 8.0),
children: <Widget>[

InkWell(
onTap:(){
Navigator.push(context,
MaterialPageRoute(builder:(context)=>resetPage()),
);
},
child: myItems(Icons.graphic_eq,"Recent Updates"),
),
InkWell (
onTap:(){
Navigator.push(context,
MaterialPageRoute(builder:(context)=>HomePage()),
);
},
child: myItems(Icons.library_books,"MMD Exams"),
),
GestureDetector(
onTap:(){
Navigator.push(context,
MaterialPageRoute(builder:(context)=>resetPage()),
);
},
child: myItems(Icons.border_color,"Blogs"),
),

myItems(Icons.assignment,"APPLICATION STATUS"),
myItems(Icons.event_note,"REGISTRATION STATUS"),
myItems(Icons.location_on,"PARCEL LOCATOR"),
myItems(Icons.crop_square,"AREASIZE CONVERTER"),
myItems(Icons.help,"HELP"),


],
staggeredTiles: [
StaggeredTile.extent(1, 170.0),
StaggeredTile.extent(1, 170.0),
StaggeredTile.extent(1, 170.0),
StaggeredTile.extent(1, 170.0),
StaggeredTile.extent(1, 170.0),
StaggeredTile.extent(1, 170.0),
],
)
);
}
}

在这里,ontap 不适用于 StaggeredgridviewTile .我的代码有什么问题?
GestureDetector(
onTap:(){
Navigator.push(context,
MaterialPageRoute(builder:(context)=>resetPage()),
);
},
child: myItems(Icons.border_color,"Blogs"),
),

gridview 不适用于 onTap() .问题是什么?

最佳答案

使用 InkWell 代替手势

InkWell(
onTap:(){
Navigator.push(context,
MaterialPageRoute(builder:(context)=>resetPage()),
);
},
child: myItems(Icons.border_color,"Blogs"),
),

关于flutter - 交错 GridView Flutter onTap 不适用于我的代码中的 tile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62423847/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com