如何 select 从 gridview 中获取图像而不用在 flutter 中重建 future builder

How to select image from gridview without rebuild the future builder in flutter

我正在尝试 select 图片并在 select 编辑图片时给它们背景。我的问题是当我 select 图像时,未来的构建器再次从数据库重新加载图像,所以我的 selected 图像无法看到。我想在不重新加载 it.Also 的情况下保留数据库中的数据,当我使用滑块放大或缩小以画廊未来的构建器重新加载数据时,它现在提供了流畅的体验。我希望我的问题是可以理解的?

return Scaffold(
  appBar: AppBar(
    title: Text(
      "Image",
    ),
    elevation: 0,
    actions: <Widget>[
      IconButton(
        icon: Icon(
          Icons.add,
          color: Colors.white,
        ),
        onPressed: () => scan(context, selectLocation.id),
      )
    ],
    backgroundColor: Colors.transparent,
  ),
  body: FutureBuilder(
    future: Provider.of<Images>(context, listen: false).fetchAndSetPlaces(),
    builder: (ctx, snapshot) => snapshot.connectionState ==
    ConnectionState.waiting
    ? Center(
      child: CircularProgressIndicator(),
    )
    : Column(
      children: [
        Expanded(
          flex: 2,
          child: Container(
            padding: EdgeInsets.only(
              top: 30, bottom: 1, left: 40, right: 40),
            child: Consumer<Images>(
              builder: (ctx, titles, ch) => GridView.builder(
                physics: ScrollPhysics(),
                itemCount: titles.items.length,
                gridDelegate:
                SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: getSize(_currentSliderValue),
                  mainAxisSpacing: 50,
                  childAspectRatio: 0.8,
                  crossAxisSpacing: 5,
                ),
                itemBuilder: (ctx, index) {
                  return GestureDetector(
                    onTap: () => add(titles.items[index].image),
                    child: Container(
                      color: selectedCard == index
                      ? Colors.blue
                      : Colors.green,
                      child: Image.file(titles.items[index].image),
                    ),
                  );
                },
              ),
            ),
          ),
        ),
        Expanded(
          child: Container(
            padding: EdgeInsets.only(left: 30, right: 30),
            child: Theme(
              data: Theme.of(context).copyWith(
                accentTextTheme: TextTheme(
                  bodyText2: TextStyle(color: Colors.white)),
              ),
              child: Slider(
                inactiveColor: Colors.purple,
                activeColor: Colors.purple,
                value: _currentSliderValue,
                min: 0,
                max: 2,
                divisions: 2,
                label: _currentSliderValue.round().toString(),
                onChanged: (double value) {
                  setState(() {
                    _currentSliderValue = value;
                  });
                },
              ),
            ),
          ),
        ),
      ],
    ),
  ),
);

尝试在初始状态或 DidChangeDependencies 中调用您的函数覆盖状态的函数 class 而不是使用 Future Builder 因此它不会从数据库重新加载图像,因为它只会调用一次。 希望你能明白我的意思,否则你可以在下面发表评论