Тип аргумента «Панель вкладок» не может быть присвоен типу параметра «Строка»

#string #flutter #dart

Вопрос:

Здравствуйте, друзья, я столкнулся с ошибкой при вводе панели вкладок в панель пользовательских приложений,

В нем говорится: «Тип аргумента» Панель вкладок «не может быть присвоен типу параметра «Строка»».

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

итак, вот в чем проблема,

возврат по умолчанию tabcontroller( длина: 4, дочерний элемент: Каркас( Панель приложений: Кустомаппбар( заголовок: «Листья», внизу:Панель вкладок( вкладки: [ Вкладка(значок: Значок(Значки.торт))), Вкладка(значок: Значок(Значки.android)), Вкладка(значок: Значок(Значки.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 amp; 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 amp; 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 amp; 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 amp; 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,
              ),
            ),
          ),
        );
      },
    );
  }
}
 

Комментарии:

1. Вы создаете панель вкладок?

2. добавьте также пользовательский код панели приложений… чтобы было легко отладить ошибку

3. Я добавил это, окончательный размер предпочтительного размера; Цвет? backgroundColor; Строка внизу; Заголовок строки; bool containTabBar; TabController? tabController; bool isCenterTitle; двойной? высота; Кустомаппбар( {Ключ? ключ, этот.backgroundColor, этот.bottom = «, этот.title = «, этот.containTabBar = false, этот.tabController, этот.isCenterTitle = false, этот.высота}) : Предпочтительный размер = Размер.fromHeight(containTabBar ? 100.0 : 50.0), супер(ключ: ключ);

Ответ №1:

Мне это удалось, @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);