Home > Software design >  WatchBoxBuilder is deprecated and shouldn't be used
WatchBoxBuilder is deprecated and shouldn't be used

Time:05-01

In flutter watchboxbuilder is deprecated, can someone help me with this,the full code is here on the 143 line

child: WatchBoxBuilder(
                              box: Hive.box<Articles>('bookmarks'),
                              builder: (context, box) => Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  GestureDetector(
                                    onTap: () => handleBookmarks(article),
                                    child: Text(
                                      article.title,
                                      style: box.containsKey(article.url)
                                          ? AppTextStyle.newsTitle
                                              .copyWith(color: AppColor.accent)
                                          : AppTextStyle.newsTitle,
                                      overflow: TextOverflow.ellipsis,
                                      maxLines: 4,
                                    ),

CodePudding user response:

WatchBoxBuilder is replaced with box.listenable().

Here is new code,

ValueListenableBuilder(
            valueListenable: Hive.box('settings').listenable(),
            builder: (context, box, child) => Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
            GestureDetector(
            onTap: () => handleBookmarks(article),
  child: Text(
    article.title,
    style: box.containsKey(article.url)
        ? AppTextStyle.newsTitle
        .copyWith(color: AppColor.accent)
        : AppTextStyle.newsTitle,
    overflow: TextOverflow.ellipsis,
    maxLines: 4,
  ),
)

For more info https://pub.dev/packages/hive_flutter/changelog#0301

  • Related