微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ObjectBox 生成器:错误:没有名为“lazy”的命名参数

如何解决ObjectBox 生成器:错误:没有名为“lazy”的命名参数

我使用此方法将我的 ObjectBox Store 注册为 LazySingleton

setupLocatorAdditions() async {
  stackedAdditionLocator.registerLazySingletonAsync<Store>(() => openStore());
}

效果很好。但是从 buildrunner 多次重建后,ObjectBox Generator 抛出了这个错误,不管我是否删除了单例注册并重新运行它。

lib/objectBox.g.dart:1341:67: Error: No named parameter with the name 'lazy'.
              weekDays: const fb.ListReader<int>(fb.Int8Reader(),lazy: false)
                                                                  ^^^^
../../Flutter/Flutter/.pub-cache/hosted/pub.dartlang.org/objectBox-1.1.1/lib/flatbuffers/flat_buffers.dart:994:9: Context: Found this candidate,but the arguments don't match.
  const ListReader(this._elementReader);
        ^^^^^^^^^^

lib/objectBox.g.dart:1343:68: Error: No named parameter with the name 'lazy'.
              locations: const fb.ListReader<int>(fb.Int8Reader(),lazy: false)
                                                                   ^^^^
../../Flutter/Flutter/.pub-cache/hosted/pub.dartlang.org/objectBox-1.1.1/lib/flatbuffers/flat_buffers.dart:994:9: Context: Found this candidate,but the arguments don't match.

  const ListReader(this._elementReader);
        ^^^^^^^^^^
2

FAILURE: Build Failed with an exception.

解决方法

该参数不是已发布的 objectbox-dart v1.1.1 的一部分(它是由 this commit 在 13 天前添加的,而 v1.1.1 是在 19 天前发布的)。

看起来您使用的是不匹配的生成器?如果您在 objectbox_generator 上使用依赖覆盖,您可以检查您的 replace,例如来自 git?如果你使用依赖覆盖,你应该坚持一个特定的提交,并确保你在生成器和 objectbox 库本身上使用它。如果您不需要依赖项覆盖,只需将其从您的 private val firstFragment = firstFragment() private val secondFragment = secondFragment() private val thirdFragment = thirdFragment() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) navView = findViewById(R.id.nav_view) sharedViewModel = ViewModelProvider(this).get(SharedViewModel::class.java) navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener) navView.menu.findItem(R.id.navigation_FIRST).isChecked = true supportFragmentManager.beginTransaction() .replace(R.id.nav_host_fragment,firstFragment) .replace(R.id.nav_host_fragment,secondFragment) .replace(R.id.nav_host_fragment,thirdFragment) .commit() setTabStateFragment(TabState.FIRST).commit() } override fun onBackPressed() { if (supportFragmentManager.backStackEntryCount > 0 || !firstFragment.isHidden){ super.onBackPressed() } else { setTabStateFragment(TabState.FIRST).commit() navView.menu.findItem(R.id.navigation_FIRST).isChecked = true } } private fun setTabStateFragment(state: TabState): FragmentTransaction { supportFragmentManager.popBackStack(null,FragmentManager.POP_BACK_STACK_INCLUSIVE) val transaction = supportFragmentManager.beginTransaction() when (state) { TabState.FIRST -> { transaction.show(firstFragment) transaction.hide(secondFragment) transaction.hide(thirdFragment) } TabState.SECOND -> { transaction.hide(firstFragment) transaction.show(secondFragment) transaction.hide(thirdFragment) } TabState.THIRD -> { transaction.hide(firstFragment) transaction.hide(secondFragment) transaction.show(thirdFragment) } } return transaction } private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> when (item.itemId) { R.id.navigation_FIRST -> { setTabStateFragment(TabState.FIRST).commit() return@OnNavigationItemSelectedListener true } R.id.navigation_second -> { setTabStateFragment(TabState.SECOND).commit() return@OnNavigationItemSelectedListener true } R.id.navigation_third -> { setTabStateFragment(TabState.THIRD).commit() return@OnNavigationItemSelectedListener true } } false } internal enum class TabState { FIRST,SECOND,THIRD,} 中删除。

在这两种情况下,进行更改后运行 pubspec.yamlpubspec.yaml

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。