提问人:kcbibek43 提问时间:4/2/2023 更新时间:4/2/2023 访问量:598
抛出以下_TypeError构建 HomePage(dirty, dependencies: [MediaQuery]): 类型“int”不是类型“double”的子类型
The following _TypeError was thrown building HomePage(dirty, dependencies: [MediaQuery]): type 'int' is not a subtype of type 'double'
问:
import 'package:first/app_styles.dart';
import 'package:first/custom_tab_indicator.dart';
import 'package:first/size_config.dart';
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: HomePage(),
),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
SizeConfig().init(context);
return SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
children: [
Container(
color: kBackgroundColor,
padding: const EdgeInsets.only(
top: 52,
left: 24,
right: 24,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Row(
children: [
Text(
'All Inboxes',
style: kJakartaHeading1.copyWith(
color: kDarkColor,
fontSize: SizeConfig.blockSizeHorizontal! * kHeading1
),
),
const Icon(Icons.expand_more)
],
),
Text('Total 2500 Messages , 3 Unread',
style: kJakartaBodyMedium.copyWith(
color: kParagraphColor,
fontSize: SizeConfig.blockSizeHorizontal! * kBody1,
),
)
],
),
const CircleAvatar(
maxRadius: 26,
backgroundColor: kSecondaryColor,
foregroundImage: NetworkImage("https://scontent.fbbi3-1.fna.fbcdn.net/v/t39.30808-6/290811895_737811837530600_5631746207860732425_n.jpg?_nc_cat=111&ccb=1-7&_nc_sid=174925&_nc_ohc=bC4YJN-G7XMAX9ScsYO&_nc_ht=scontent.fbbi3-1.fna&oh=00_AfDDgP91zqk5w95CPZegQJrNGLNGAOnJ2c1bPejkP8drGQ&oe=642CDE70"),
)
]
),
),
Container(
height: 28,
color: kBackgroundColor,
child: SizedBox(
height: 98,
child: ListView.builder(
itemCount: 10,
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
itemBuilder: (context,index) {
return Container(
margin: EdgeInsets.only(
left: index == 0 ? 24 : 0,
right: index == 9 ? 24 : 8,
),
child: Column(
children: [
Stack(
children: [
const CircleAvatar(
maxRadius: 36,
backgroundColor: kWhiteColor,
foregroundImage: NetworkImage("https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.iconfinder.com%2Ficons%2F7123025%2Flogo_google_g_icon&psig=AOvVaw1P3y-6z6_Kqz7EkyFOa6mR&ust=1680431544395000&source=images&cd=vfe&ved=0CBAQjRxqFwoTCLiI8729iP4CFQAAAAAdAAAAABAD"),
),
Positioned(
right: 0,
left: 0,
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 2,
horizontal: 8,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: kPrimaryColor,
),
child: IntrinsicWidth(
child: Text('12',
style: kJakartaBodyBold.copyWith(
color: kWhiteColor,
fontSize: SizeConfig.blockSizeHorizontal! * kBody2,
),
),
),
),
)
],
),
const SizedBox(height: 8,
),
Text('Google',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: kJakartaBodyMedium.copyWith(
color: kParagraphColor,
fontSize: SizeConfig.blockSizeHorizontal! * kBody1,
),
),
],
),
);
}
),
),
),
Container(
height: 48,
color: kBackgroundColor,
),
Container(
height: 30,
transform: Matrix4.translationValues(0, -24, 0),
decoration:const BoxDecoration(
color: kWhiteColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(32),
topRight: Radius.circular(32)
)
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 24
),
transform: Matrix4.translationValues(0, -36, 0),
height: 30,
child: Row(
children: [
Expanded(
child: Container(
alignment: Alignment.topLeft,
child: DefaultTabController(
length: 3,
child: TabBar(
labelPadding: const EdgeInsets.only( right: 24),
indicatorWeight: 8,
isScrollable: true,
labelColor: kDarkColor,
labelStyle: kJakartaBodyBold.copyWith(
fontSize: SizeConfig.blockSizeHorizontal! * kBody1,
),
unselectedLabelColor: kDark40Color,
indicator: RoundedRectangleTabIndicator(color: kPrimaryColor, weight: 4, width: 24, padding: 12),
splashFactory: NoSplash.splashFactory,
overlayColor: MaterialStateProperty.resolveWith((states) => states.contains(MaterialState.focused) ? null : Colors.transparent,)
,tabs: const [
Tab(text: 'Primary',),
Tab(text: 'Socia;',),
Tab(text: 'Forums',),
]
),
),
),
),
SizedBox( height: 19.5,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
const Icon(Icons.more_horiz),
const SizedBox(width: 24),
Text('Edit',
style: kJakartaBodyBold.copyWith(
color: kDark40Color,
fontSize: SizeConfig.blockSizeHorizontal! * kBody1,
),
)
],
),
)
],
),
),
// Container(
// padding: EdgeInsets.only(top: 16),
// transform: Matrix4.translationValues(0, -36, 0),
// child: ListView.builder(itemBuilder: ),
// )
],
),
);
}
}
我是 flutter 的新手。我试图运行该应用程序,但它显示此错误。 ══╡ 小部件库捕获的异常 ╞═══════════════════════════════════════════════════════════ 抛出以下_TypeError构建 HomePage(dirty, dependencies: [MediaQuery]): 类型“int”不是类型“double”的子类型
导致错误的相关小部件是: 主页主页:file:///D:/UI%20under%20FLutter/first/lib/main.dart:16:16
抛出异常时,这是堆栈: #0 新的 RoundedRectangleTabIndicator (package:first/custom_tab_indicator.dart:11:65) #1 HomePage.build(包:first/main.dart:173:36) #2 StatelessElement.build (软件包:flutter/src/widgets/framework.dart:5038:49) #3 ComponentElement.performRebuild (软件包:flutter/src/widgets/framework.dart:4968:15) #4 Element.rebuild (软件包:flutter/src/widgets/framework.dart:4690:5) #5 ComponentElement._firstBuild (软件包:flutter/src/widgets/framework.dart:4950:5) #6 ComponentElement.mount (软件包:flutter/src/widgets/framework.dart:4944:5) ...普通元件安装(25 个框架) #31 Element.inflateWidget (软件包:flutter/src/widgets/framework.dart:3953:16) #32 MultiChildRenderObjectElement.inflateWidget (软件包:flutter/src/widgets/framework.dart:6512:36) #33 MultiChildRenderObjectElement.mount (软件包:flutter/src/widgets/framework.dart:6524:32) ...普通元件安装(318 帧) #351 Element.inflateWidget (软件包:flutter/src/widgets/framework.dart:3953:16) #352 MultiChildRenderObjectElement.inflateWidget (软件包:flutter/src/widgets/framework.dart:6512:36) #353 MultiChildRenderObjectElement.mount (软件包:flutter/src/widgets/framework.dart:6524:32) ...普通元件安装(452 个框架) #805 Element.inflateWidget (软件包:flutter/src/widgets/framework.dart:3953:16) #806 Element.updateChild (软件包:flutter/src/widgets/framework.dart:3682:18) #807 RenderObjectToWidgetElement._rebuild (软件包:flutter/src/widgets/binding.dart:1176:16) #808 RenderObjectToWidgetElement.mount (软件包:flutter/src/widgets/binding.dart:1145:5) #809 RenderObjectToWidgetAdapter.attachToRenderTree。(软件包:flutter/src/widgets/binding.dart:1092:18) #810 BuildOwner.buildScope (软件包:flutter/src/widgets/framework.dart:2682:19) #811 RenderObjectToWidgetAdapter.attachToRenderTree (软件包:flutter/src/widgets/binding.dart:1091:13) #812 WidgetsBinding.attachRootWidget (软件包:flutter/src/widgets/binding.dart:926:7) #813 WidgetsBinding.scheduleAttachRootWidget。(软件包:flutter/src/widgets/binding.dart:906:7) #817 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26) (从类 _Timer 和 dart:async-patch 中省略了 3 帧)
答:
要传递给 RoundedRectangleTabIndicator 的一个或多个参数值应为双精度值。您正在使用整数。您在堆栈中获得的信息非常具体且有用。你需要阅读和理解它。
此外,您的 IDE 应该能够向您指示参数的类型。
评论