I want to take images from asset in gridview flutter and want to make it clickable, but I am getting error with this code
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../home1_page.dart';
class ItemdetailAccelero extends StatefulWidget {
const ItemdetailAccelero({
Key? key,
}) : super(key: key);
@override
State<ItemdetailAccelero> createState() => _ItemdetailAcceleroState();
}
class _ItemdetailAcceleroState extends State<ItemdetailAccelero> {
List<String> images = [
"assets/images/freerun.png",
"assets/images/hammer.png",
"assets/images/soccer.png",
"assets/images/linefollower.png"
];
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
backgroundColor: Color.fromARGB(255, 212, 235, 249),
appBar: AppBar(
/* actions: [IconButton(onPressed: () => Get.off(const HomeScreen()), icon: const Icon(Icons.arrow_back_ios))], */ backgroundColor:
Colors.transparent,
elevation: 0,
title: Text('Accelero', style: TextStyle(fontSize: 20))),
body: SafeArea(
child: Stack(children: [
Hero(
tag: 'Accelero',
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width * 0.8,
decoration: const BoxDecoration(
color: Color.fromARGB(255, 197, 228, 248),
image: DecorationImage(
image: AssetImage(
'assets/images/Accelero.png',
),
fit: BoxFit.contain,
),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: MediaQuery.of(context).size.height * .6,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white.withOpacity(.1),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
),
boxShadow: [
BoxShadow(
color: Color.fromARGB(255, 231, 43, 43).withOpacity(.2),
offset: Offset(0, -7),
blurRadius: 0.2),
]),
child: GridView.builder(
itemCount: images.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0
),
itemBuilder: (BuildContext context, int index){
return Image.asset(images[index]);
},
),
),
)
]),
),
);
}
}
图像资源服务捕获异常无法加载资产:assets/images/soccer.png.足球俱乐部/足球俱乐部/足球俱乐部
图像资源服务捕获异常无法加载资产:assets/images/linefollower.png.网络资源/图片资源/linefollower.png.
微件库捕获到异常。ParentDataWidget的使用不正确。
1条答案
按热度按时间siv3szwd1#
flutter clean
和flutter pub get
命令之后这肯定管用