Reputation: 11
I am not understanding the error and where it is. Can you help me please?
This is the error message:
======== Exception caught by widgets library =======================================================
The following _CastError was thrown building:
type 'Padding' is not a subtype of type 'IconData' in type cast
When the exception was thrown, this was the stack:
#0 TodayTaskView.build.<anonymous closure>.<anonymous closure> (package:taskly/app/modules/home/views/today_task_view.dart:151:31)
And this is my homepage view code:
import 'package:bubble_bottom_bar/bubble_bottom_bar.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
import 'package:taskly/app/global_widgets/bottom_sheet.dart';
import 'package:taskly/app/modules/home/controllers/home_controller.dart';
import 'package:taskly/app/theme/text_theme.dart';
class HomeView extends GetView<HomeController> {
final controller = Get.put(HomeController());
@override
Widget build(BuildContext context) {
controller.getUser();
return Scaffold(
body: Obx(() => controller.navBarSwitcher()),
floatingActionButton: FloatingActionButton(
onPressed: () {
controller.controllerReset();
showModalBottomSheet(
backgroundColor: Colors.transparent,
isScrollControlled: true,
context: context,
builder: (context) {
return BottomSheetContent(
buttonText: 'Create Task',
onSubmit: () {
controller.addTask();
},
);
},
);
},
child: Icon(
Icons.add,
color: Theme.of(context).scaffoldBackgroundColor,
),
backgroundColor: Theme.of(context).primaryColor,
elevation: 3,
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
bottomNavigationBar: Obx(
() => BubbleBottomBar(
opacity: 0,
fabLocation: BubbleBottomBarFabLocation.end,
currentIndex: controller.currentIndex,
backgroundColor: Theme.of(context).primaryColorLight,
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
hasInk: false,
elevation: 7,
inkColor: Colors.black54,
hasNotch: true,
onTap: (index) => controller.currentIndex = index,
items: [
BubbleBottomBarItem(
backgroundColor: Colors.grey,
title: Text(
'Home',
style: kSub2HeadTextStyle.copyWith(fontSize: 16),
),
icon: Icon(
// FontAwesomeIcons.home,
FontAwesomeIcons.house,
color: Theme.of(context).primaryColorDark,
),
// activeIcon: Icon(FontAwesomeIcons.home,
activeIcon: Icon(
FontAwesomeIcons.house,
color: Theme.of(context).primaryColor,
),
),
BubbleBottomBarItem(
backgroundColor: Colors.grey,
title: Text(
'Tasks',
style: kSub2HeadTextStyle.copyWith(fontSize: 16),
),
icon: Icon(
FontAwesomeIcons.listUl,
color: Theme.of(context).primaryColorDark,
),
activeIcon: Icon(FontAwesomeIcons.listUl,
color: Theme.of(context).primaryColor),
),
// BubbleBottomBarItem(
// backgroundColor: Colors.grey,
// title: Text(
// 'To-do',
// style: kSub2HeadTextStyle.copyWith(fontSize: 16),
// ),
// icon: Icon(
// FontAwesomeIcons.tasks,
// color: Theme.of(context).primaryColorDark,
// ),
// activeIcon: Icon(FontAwesomeIcons.tasks,
// color: Theme.of(context).primaryColor),
// ),
],
),
),
);
}
}
While this is my today_task_view code:
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';
import 'package:taskly/app/global_widgets/bottom_sheet.dart';
import 'package:taskly/app/global_widgets/expandable_container.dart';
import 'package:taskly/app/modules/home/controllers/home_controller.dart';
import 'package:taskly/app/theme/text_theme.dart';
class TodayTaskView extends GetView<HomeController> {
@override
Widget build(BuildContext context) {
return Container(
height: Get.height,
width: Get.width,
color: Theme.of(context).scaffoldBackgroundColor,
//padding: EdgeInsets.symmetric(horizontal: 30, vertical: 50),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(top: 50, left: 25, right: 25),
child: Text(
'Today\'s Tasks',
style: kSubHeadTextStyle.copyWith(
color: Theme.of(context).primaryColorDark),
),
),
SizedBox(height: Get.height * 0.012),
GetBuilder<HomeController>(
id: 1,
builder: (controller) {
return Expanded(
child: ListView.builder(
itemBuilder: (context, index) {
final task = controller.todayTasks[index]!;
return Slidable(
// actionPane: SlidableBehindActionPane(),
// actionExtentRatio: 0.2,
// controller: controller.slideC,
child: ExpandedContainer(
icon: task.taskImage,
title: task.taskTitle,
time: task.startTime,
desc: task.taskDesc,
),
// actions: [
// Padding(
// padding: EdgeInsets.only(
// bottom: Get.width * 0.05,
// left: Get.width * 0.07),
// child: Container(
// padding: EdgeInsets.all(0),
// width: 40,
// height: 40,
// decoration: BoxDecoration(
// color: Theme.of(context).primaryColorLight,
// borderRadius: BorderRadius.circular(10)),
// child: IconButton(
// icon: Icon(
// Icons.edit,
// size: 26,
// color: Theme.of(context).primaryColorDark,
// ),
// onPressed: () {
// controller.slideC.activeState?.close();
// Slidable.of(context)?.close();
// controller.preUpdateTask(task);
// showModalBottomSheet(
// backgroundColor: Colors.transparent,
// isScrollControlled: true,
// context: context,
// builder: (context) {
// return BottomSheetContent(
// buttonText: 'Update Task',
// onSubmit: () {
// controller.updateTask(task);
// },
// );
// },
// );
// }),
// ),
// ),
// ],
// secondaryActions: [
// Padding(
// padding: EdgeInsets.only(
// bottom: Get.width * 0.05,
// right: Get.width * 0.07),
// child: Container(
// padding: EdgeInsets.all(0),
// width: 40,
// height: 40,
// decoration: BoxDecoration(
// color: Theme.of(context).primaryColorLight,
// borderRadius: BorderRadius.circular(10)),
// child: IconButton(
// icon: Icon(
// Icons.delete,
// size: 26,
// color: Theme.of(context).primaryColorDark,
// ),
// onPressed: () {
// controller.slideC.activeState?.close();
// Slidable.of(context)?.close();
// controller.customDialogDel(context, task);
// }),
// ),
// ),
// ],
startActionPane: ActionPane(
motion: BehindMotion(),
children: [
SlidableAction(
onPressed: (context) {
// controller.slideC.activeState?.close();
Slidable.of(context)?.close();
controller.preUpdateTask(task);
showModalBottomSheet(
backgroundColor: Colors.transparent,
isScrollControlled: true,
context: context,
builder: (context) {
return BottomSheetContent(
buttonText: 'Update Task',
onSubmit: () {
controller.updateTask(task);
},
);
},
);
},
icon: Padding(
padding: EdgeInsets.only(
bottom: Get.width * 0.05,
left: Get.width * 0.07,
),
child: Container(
padding: EdgeInsets.all(0),
width: 40,
height: 40,
decoration: BoxDecoration(
color: Theme.of(context).primaryColorLight,
borderRadius: BorderRadius.circular(10)),
child: Icon(
Icons.edit,
size: 26,
color: Theme.of(context).primaryColorDark,
),
),
) as IconData,
label: "Update",
),
],
),
endActionPane: ActionPane(
motion: BehindMotion(),
children: [
SlidableAction(
onPressed: (context) {
// controller.slideC.activeState?.close();
Slidable.of(context)?.close();
controller.customDialogDel(context, task);
},
icon: Padding(
padding: EdgeInsets.only(
bottom: Get.width * 0.05,
right: Get.width * 0.07,
),
child: Container(
padding: EdgeInsets.all(0),
width: 40,
height: 40,
decoration: BoxDecoration(
color: Theme.of(context).primaryColorLight,
borderRadius: BorderRadius.circular(10)),
child: Icon(
Icons.delete,
size: 26,
color: Theme.of(context).primaryColorDark,
),
),
) as IconData,
label: "Delete",
),
],
),
);
},
itemCount: controller.todayTasks.length,
),
);
},
),
],
),
);
}
}
Upvotes: 0
Views: 315
Reputation: 8607
Well, you have the following line in your code (twice), in class TodayTaskView
:
) as IconData,
And SlidableAction
wants an IconData
, and Padding
can't be cast to an IconData
IconData
is not a widget, it is just a description of an icon. It holds an int
, two String
's and a bool
.
Padding
is a widget.
Upvotes: 1