我已经为我的应用程序使用flutter制作了2个页面。文件名是HomeBanner和home_screen。我不知道是什么导致我的文件中的错误。这是HomeBanner文件:
import 'package:flutter/material.dart';
import 'package:my_portfolio/constants.dart';
class HomeBanner extends StatelessWidget {
const HomeBanner({
super.key,
});
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 3,
child: Stack(
fit: StackFit.expand,
children: [
Image.asset(
"/home/isha/Desktop/flutter_app/my_portfolio/assets/background.jpg",
fit: BoxFit.cover,
),
Container(
color: darkColor.withOpacity(0.66),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: defaultPadding),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Discover about my space!",
style: Theme.of(context).textTheme.headline3!.copyWith(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
MyApps(),
],
),
),
],
),
);
}
}
这是我的home_screen文件,我不认为我错过了任何依赖:
import 'package:flutter/material.dart';
import 'package:my_portfolio/screens/home/HomeBanner.dart';
//import 'package:my_portfolio/constants.dart';
import 'package:my_portfolio/screens/main_screen.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return MainScreen(
children: [
const HomeBanner(),
Text(
"My Projects",
style: Theme.of(context).textTheme.headlineSmall,
),
// GridView.builder(
// shrinkWrap: true,
// itemCount: 9,
// gridDelegate:
// SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
// itemBuilder: (context, index) => Container(
// color: Colors.blueGrey,
// )),
],
);
}
}
下面是错误:
Waiting for connection from debug service on Chrome...
lib/screens/home/home_screen.dart:13:15: Error: Couldn't find constructor 'HomeBanner'.
const HomeBanner(),
^^^^^^^^^^
Waiting for connection from debug service on Chrome... 42.1s
Failed to compile application.
有谁能帮上忙这个。谢谢你!
1条答案
按热度按时间k5ifujac1#
在homebanner文件中,您创建了一个无状态小部件并将其命名为HomeBanner,但小部件名称看起来像是您忘记了更改小部件的名称。因为当前您使用的类名是AdressInfo,所以使用您从主屏幕调用的HomeBanner更改类名。
从;
至;