首页 > 解决方案 > 参数类型“TabBar”不能分配给参数类型“String”

问题描述

您好朋友,我在将 tabbar 放入 customappbar 时遇到了错误,

它说“参数类型'TabBar'不能分配给参数类型'String'。”

// 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) {

现在,问题来了,

return DefaultTabController(长度: 4, child: Scaffold(appBar: CoustomAppBar(title: 'Leaves', bottom:TabBar( tabs: [ Tab(icon: Icon(Icons.cake)), Tab(icon: Icon(Icons.android) ), Tab(icon: Icon(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,
              ),
            ),
          ),
        );
      },
    );
  }
}

标签: stringflutterdart

解决方案


我已经做到了,@Why_So_Ezz

class CoustomAppBar extends StatelessWidget with PreferredSizeWidget {
  @override
  final Size preferredSize;

  Color? backgroundColor;
  String bottom;
  String title;
  bool containTabBar;
  TabController? tabController;
  bool isCenterTitle;
  double? elevation;

  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);

推荐阅读