sarina
2 سال پیش توسط sarina مطرح شد
1 پاسخ

searchappbar اونایی که دوره فلاترشرکت کردند

سلام دوستان
برای ورژن جدید دارت میشه نمونه کد searchappbar و بذارید برام(برای واتس اپ مثلا). ازsliverappbar استفاده بشه برای هاید شدن mainappbar
کلا اگ آموزش هارو دیدیدممنون میشم بگید چرامن بعد از اپدیت این ارور و برای سرچ اپپبار و.... دریافت میکنم
طبق چیزی که استاد گفتن نوشتم دقیقا


class WhatsAppHomeState extends State<WhatsAppHome>
    with SingleTickerProviderStateMixin {
  late TabController tabController;
  late Map<String, SliverAppBar> appBarList;
  String _currentAppBar = 'mainAppBar';

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    tabController = new TabController(initialIndex: 1, length: 4, vsync: this);

    SliverAppBar mainAppBar = new SliverAppBar(
      title: new Text('واتس اپ'),
      pinned: true,
      elevation: 5,
      bottom: new TabBar(
        controller: tabController,
        indicatorColor: Colors.white,
        tabs: <Widget>[
          new Tab(icon: new Icon(Icons.camera_alt)),
          new Tab(text: " چت ها"),
          new Tab(text: "وضعیت"),
          new Tab(text: "تماس ها"),
        ],
      ),
      actions: <Widget>[
        new Icon(Icons.search),
        new Padding(padding: EdgeInsets.symmetric(horizontal: 5)),
        new PopupMenuButton<String>(onSelected: (String choice) {
          print(choice);
        }, itemBuilder: (BuildContext context) {
          return [
            new PopupMenuItem(
                value: 'new_group',
                child: new Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[new Text('گروه جدید')],
                )),
            new PopupMenuItem(
                value: 'setting',
                child: new Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[new Text('تنظیمات')],
                ))
          ];
        })
      ],
    );

    appBarList = <String, SliverAppBar>{
      'mainAppBar': mainAppBar,
      'searchAppBar': mainAppBar
    };
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[appBarList[_currentAppBar]];
        },

خط اخر ارور:The element type 'SliverAppBar?' can't be assigned to the list type 'Widget'.

ارور با گذاشتن ! بین رفع شدreturn <Widget>[appBarList[_currentAppBar]!]


ثبت پرسش جدید
میلاد خسروی
تخصص : برنامه نویس بامزه
@milwad 2 سال پیش مطرح شد
0

سلام خسته نباشید
ببین دقیق این ویجت یادم نیست ولی بعضی وقت ها با گذاشتن ؟ یا ! ارور برطرف میشه چون null safe بازه


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام