【发布时间】:2021-11-14 17:26:53
【问题描述】:
朋友们好,我在将 tabbar 放入 customappbar 时遇到了错误,
它说,“参数类型 'TabBar' 不能分配给 参数类型‘字符串’。”
// ignore_for_file: import_of_legacy_library_into_null_safe, unused_import, non_constant_identifier_names
import 'package:date_time_picker/date_time_picker.dart';
import 'package:dropdown_search/dropdown_search.dart';
import 'package:e_digital_nepal/widgets/custom_appBar.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'student_leave_card.dart';
import 'student_leave_apply.dart';
import 'datepicker.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: StudentLeaveHistory(),
title: 'Leaves',
));
}
class StudentLeaveHistory extends StatefulWidget {
@override
_StudentLeaveHistoryState createState() => _StudentLeaveHistoryState();
}
class _StudentLeaveHistoryState extends State<StudentLeaveHistory>
with SingleTickerProviderStateMixin {
late Animation animation, delayedAnimation, muchDelayedAnimation, LeftCurve;
late AnimationController animationController;
@override
void initState() {
// ignore: todo
// TODO: implement initState
super.initState();
//SystemChrome.setEnabledSystemUIOverlays([]);
animationController =
AnimationController(duration: Duration(seconds: 3), vsync: this);
animation = Tween(begin: -1.0, end: 0.0).animate(CurvedAnimation(
parent: animationController, curve: Curves.fastOutSlowIn));
delayedAnimation = Tween(begin: 1.0, end: 0.0).animate(CurvedAnimation(
parent: animationController,
curve: Interval(0.2, 0.5, curve: Curves.fastOutSlowIn)));
muchDelayedAnimation = Tween(begin: -1.0, end: 0.0).animate(CurvedAnimation(
parent: animationController,
curve: Interval(0.3, 0.5, curve: Curves.fastOutSlowIn)));
}
@override
Widget build(BuildContext context) {
animationController.forward();
final double width = MediaQuery.of(context).size.width;
return AnimatedBuilder(
animation: animationController,
builder: (BuildContext context, Widget? child) {
现在,问题来了,
返回 DefaultTabController( 长度:4, 孩子:脚手架( 应用程序栏:自定义应用程序栏( 标题:'叶子', 底部:标签栏( 标签:[ 标签(图标:图标(图标.cake)), 选项卡(图标:图标(Icons.android)), 标签(图标:图标(Icons.phone_android)), ],), ),
return DefaultTabController(
length: 4,
child: Scaffold(
appBar: CoustomAppBar(
title: 'Leaves',
bottom:TabBar(
tabs: <Widget>[
Tab(icon: Icon(Icons.cake)),
Tab(icon: Icon(Icons.android)),
Tab(icon: Icon(Icons.phone_android)),
],),
),
body: SingleChildScrollView(
child: Column(children: [
Transform(
transform: Matrix4.translationValues(
delayedAnimation.value * width, 0, 0),
child: StudentLeaveHistoryCard(
leavetype: 'Cultural & Ritual Ceremony',
description:
"It is respectfully submitted that, I Subidha Shrestha from class 10 having roll no 15 is suffering from fever since last night. It seems as if that fever is not going away at all, soy father want to rush me to hospital.Therefore I, am unable to attend my school classes for next three days. I hope you will understand my situation will grant me leave for next 03 days.",
status: 'Pending',
requesteddate: '2078-05-08',
verifieddate: '2078-05-09',
),
),
SizedBox(
height: 10,
),
Transform(
transform: Matrix4.translationValues(
delayedAnimation.value * width, 0, 0),
child: StudentLeaveHistoryCard(
leavetype: 'Cultural & Ritual Ceremony',
description:
"It is respectfully submitted that, I Subidha Shrestha from class 10 having roll no 15 is suffering from fever since last night. It seems as if that fever is not going away at all, soy father want to rush me to hospital.Therefore I, am unable to attend my school classes for next three days. I hope you will understand my situation will grant me leave for next 03 days.",
status: 'Pending',
requesteddate: '2078-05-08',
verifieddate: '2078-05-09',
),
),
SizedBox(
height: 10,
),
Transform(
transform: Matrix4.translationValues(
delayedAnimation.value * width, 0, 0),
child: StudentLeaveHistoryCard(
leavetype: 'Cultural & Ritual Ceremony',
description:
"It is respectfully submitted that, I Subidha Shrestha from class 10 having roll no 15 is suffering from fever since last night. It seems as if that fever is not going away at all, soy father want to rush me to hospital.Therefore I, am unable to attend my school classes for next three days. I hope you will understand my situation will grant me leave for next 03 days.",
status: 'Pending',
requesteddate: '2078-05-08',
verifieddate: '2078-05-09',
),
),
SizedBox(
height: 10,
),
Transform(
transform: Matrix4.translationValues(
delayedAnimation.value * width, 0, 0),
child: StudentLeaveHistoryCard(
leavetype: 'Cultural & Ritual Ceremony',
description:
"It is respectfully submitted that, I Subidha Shrestha from class 10 having roll no 15 is suffering from fever since last night. It seems as if that fever is not going away at all, soy father want to rush me to hospital.Therefore I, am unable to attend my school classes for next three days. I hope you will understand my situation will grant me leave for next 03 days.",
status: 'Pending',
requesteddate: '2078-05-08',
verifieddate: '2078-05-09',
),
),
SizedBox(
height: 10,
),
]),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => StudentLeaveApply()),
);
},
child: Icon(
Icons.add,
color: Colors.white,
size: 20,
),
),
),
);
},
);
}
}
【问题讨论】:
-
你在创建 TabBar 吗?
-
添加自定义Appbar代码...方便调试错误
-
我已经添加了这个,最终尺寸首选尺寸;颜色?背景颜色;弦底;字符串标题;布尔包含标签栏;标签控制器?选项卡控制器; bool isCenterTitle;双倍的?海拔; CoustomAppBar({Key?key, this.backgroundColor, this.bottom = '', this.title = '', this.containTabBar = false, this.tabController, this.isCenterTitle = false, this.elevation}) : preferredSize = Size .fromHeight(containTabBar ? 100.0 : 50.0), super(key: key);