Как я могу анимировать SliverAppBar для закрепления, а также прокручивать поверх customscrollview? flutter

#android #flutter #dart

#Android #flutter #дротик

Вопрос:

Я должен сделать эту панель приложений Sliverapp такой, я уже пробовал устанавливать параметры, как я делал в видео (привязка: false, плавающая: false, закрепленная: true), но, похоже, не работает, есть идеи?

 Widget build(BuildContext context) {
    PerpetualData dark = Provider.of<PerpetualData>(context);
    Color contrastColor = Color(dark.isDark ? 0xFFFFFFFF : 0xFF202020);
    Color backgroundColor = Color(dark.isDark ? 0xFF202020 : 0xFFFFFFFF);
    Color searchBar = Color(dark.isDark ? 0xFF404040 : 0xFFEEEEEE);
    return FutureBuilder(
        initialData: [],
        future: initialize(),
        builder: (context, snapshot) {
          return Scaffold(
            backgroundColor: backgroundColor,
            body: AnnotatedRegion(
              value: SystemUiOverlayStyle(
                  systemNavigationBarColor: backgroundColor),
              child: ScrollConfiguration(
                behavior: RemovedBeheavior(),
                child: CustomScrollView(
                  shrinkWrap: true,
                  reverse: dark.scrollDir,
                  slivers: [
                    SliverAppBar(
                      elevation: 0,
                      backgroundColor: backgroundColor,
                      toolbarHeight: 150,
                      automaticallyImplyLeading: false,
                      flexibleSpace: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          IconButton(
                            icon: Icon(
                              Icons.add,
                              color: contrastColor,
                              size: 36,
                            ),
                            onPressed: () async {
                              print("Pressed");
                              File file;
                              File((await getApplicationDocumentsDirectory())
                                      .path  
                                  "/Notes/${Uuid().v1()}.txt")
                                ..create(recursive: true).then((File fl) {
                                  file = fl;
                                }).whenComplete(() {
                                  Map<String, dynamic> toWrite = {
                                    "color": "0xFFFFCA28",
                                    "contents": ""
                                  };
                                  file.writeAsString(toWrite.toString());
                                  Navigator.pop(context);

                                  SystemChrome.setEnabledSystemUIOverlays([]);
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                      builder: (context) =>
                                          NoteStateful(filePath: file.path),
                                    ),
                                  );
                                });
                            },
                          ),
                        ],
                      ),
                      actions: [
                        Padding(
                          padding: EdgeInsets.only(
                              bottom: MediaQuery.of(context).size.height / 9),
                          child: IconButton(
                            onPressed: () {
                              print("Pressed settings");
                              Navigator.pop(context);
                              Navigator.push(
                                context,
                                MaterialPageRoute(
                                  builder: (context) => Settings(),
                                ),
                              );
                            },
                            icon: Icon(
                              Icons.settings,
                              color: contrastColor,
                              size: 30,
                            ),
                          ),
                        ),
                      ],
                      title: Container(
                        child: Wrap(
                          children: [
                            Divider(
                              height: 30,
                              color: Colors.transparent,
                            ),
                            Text(
                              "Memo",
                              style: TextStyle(color: contrastColor),
                            ),
                            Divider(
                              height: 10,
                              color: Colors.transparent,
                            ),
                            Container(
                              height: 50,
                              child: TextField(
                                focusNode: searchNode,
                                cursorColor: Color(0xFFCCCCCC),
                                decoration: InputDecoration(
                                  border: OutlineInputBorder(
                                    borderSide: BorderSide(
                                        color: searchBar, width: 2.0),
                                  ),
                                  focusedBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                        color: searchBar, width: 2.0),
                                  ),
                                  errorBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                        color: searchBar, width: 2.0),
                                  ),
                                  disabledBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                        color: searchBar, width: 2.0),
                                  ),
                                  fillColor: searchBar,
                                  focusColor: searchBar,
                                  hoverColor: searchBar,
                                  suffixIcon: IconButton(
                                    visualDensity:
                                        VisualDensity.adaptivePlatformDensity,
                                    splashColor: Colors.transparent,
                                    highlightColor: Colors.transparent,
                                    onPressed: () {
                                      searchNode.unfocus();
                                    },
                                    icon: Icon(Icons.search),
                                    color: Color(0xFF909090),
                                  ),
                                  enabledBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                        color: searchBar, width: 2.0),
                                  ),
                                  hintText: 'Cerca...',
                                  hintStyle: TextStyle(
                                      color: Color(0xFF909090), height: 2.7),
                                ),
                              ),
                              decoration: BoxDecoration(
                                color: searchBar,
                                border:
                                    Border.all(width: 4.0, color: searchBar),
                                borderRadius: BorderRadius.circular(0.0),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    SliverToBoxAdapter(
                        child: Divider(
                      height: 25,
                      color: Colors.transparent,
                    )),
                    snapshot.data.length > 0
                        ? SliverList(
                            delegate: SliverChildBuilderDelegate(
                              (BuildContext context, int index) {
                                return FutureBuilder(
                                  initialData: {
                                    "color": "0xFF202020",
                                    "contents": "Aggiungi una nota...",
                                    "textColor": "grey"
                                  },
                                  future: FileManager()
                                      .readFile(snapshot.data[index].path),
                                  builder: (BuildContext innerContext,
                                      AsyncSnapshot<Map<String, dynamic>>
                                          innerSnapshot) {
                                    if (!snapshot.hasData)
                                      return Center(
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: <Widget>[
                                            CircularProgressIndicator(
                                              backgroundColor: Colors.red[900],
                                            )
                                          ],
                                        ),
                                      );
                                    Map<String, dynamic> fileData =
                                        innerSnapshot.data;
                                    return Padding(
                                      padding: const EdgeInsets.symmetric(
                                          horizontal: 18, vertical: 5),
                                      child: GestureDetector(
                                        onTap: () {
                                          SystemChrome
                                              .setEnabledSystemUIOverlays([]);
                                          Navigator.pop(context);
                                          Navigator.push(
                                            context,
                                            MaterialPageRoute(
                                              builder: (context) =>
                                                  NoteStateful(
                                                      filePath: snapshot
                                                          .data[index].path),
                                            ),
                                          );
                                        },
                                        child: Container(
                                          width: 200,
                                          height: 100,
                                          decoration: BoxDecoration(
                                              color: contrastColor.value !=
                                                      0xFFFFFFFF
                                                  ? Color(
                                                      int.parse(
                                                          fileData["color"]),
                                                    ).withAlpha(134)
                                                  : Color(0xFF333333),
                                              borderRadius: BorderRadius.all(
                                                  Radius.circular(3))),
                                          child: Wrap(
                                            children: [
                                              Container(
                                                height: 10,
                                                decoration: BoxDecoration(
                                                  color: Color(
                                                    int.parse(
                                                        fileData["color"]),
                                                  ),
                                                  borderRadius:
                                                      BorderRadius.only(
                                                          topLeft: Radius
                                                              .circular(3),
                                                          topRight:
                                                              Radius.circular(
                                                                  3)),
                                                ),
                                              ),
                                              Padding(
                                                padding:
                                                    const EdgeInsets.symmetric(
                                                        vertical: 20,
                                                        horizontal: 15),
                                                child: Text(
                                                  fileData["contents"],
                                                  style: TextStyle(
                                                    color:
                                                        fileData["textColor"] ==
                                                                "contrastColor"
                                                            ? contrastColor
                                                            : Color(0xFFCCCCCC),
                                                    fontSize: 20,
                                                  ),
                                                ),
                                              )
                                            ],
                                          ),
                                        ),
                                      ),
                                    );
                                  },
                                );
                              },
                              childCount: snapshot.data.length,
                            ),
                          )
                        : SliverToBoxAdapter(
                            child: Container(
                              child: Text("aiuto"),
                            ),
                          ),
                    SliverToBoxAdapter(
                        child: Divider(
                      height: 20,
                      color: Colors.transparent,
                    )),
                  ],
                ),
              ),
            ),
          );
        });
  }
}
 

я знаю, что код довольно запутанный, но это единственный известный мне способ заставить это работать, я хочу использовать sliver, а не анимировать панель приложений, потому что я думаю, что этот способ немного лучше для этого случая

РЕДАКТИРОВАТЬ: я действительно не знаю, почему, но параметр shrinkWrap в CustomScrollView помешал мне добиться этого, я просто установил shrinkWrap в false, установил параметры AppBar следующим образом: закрепленный: true, привязка: false, плавающий: false и играл с параметрами высот и работал 🙂

Ответ №1:

добавить свойство pinned: true в Sliverappbar

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

1. Привет! спасибо за ответ, но добавление этого приведет к тому, что SliverList будет перекрывать панель приложений

2. удаление вашей термоусадочной пленки из customscrollview исправит