I dont know why it is not working. My ValueListenableBulder is empty and I dont know why. I am new in coding and new in dart. I get an "Bad State: No element" error
It would make me happy if i just get an output if I have something in my list and if not it should print nothing
I dont know why my ListView.builder has nothing in it, and I also do not know how to write a fallback for that problem.
I hope you understand my problem. If you need more information so please just leave a comment on this.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: const Icon(
MyFlutterApp.teckproLog,
size: 50,
),
centerTitle: true,
title: const Text("Authenticator"),
actions: [
IconButton(
onPressed: () => Hive.box(HiveBoxes.otpStrings.name)
.add("otpauth://totp/ASFA?secret=ASDD"),
icon: const Icon(Icons.add))
],
),
body: ValueListenableBuilder(
valueListenable: Hive.box(HiveBoxes.otpStrings.name).listenable(),
builder: (context, box, _) {
List<OtpModel> otpObjects = box.values
.map((otpString) => OtpModel.fromUri(otpString))
.toList();
return ListView.builder(
itemCount: otpObjects.reversed.length,
itemBuilder: (BuildContext context, index) {
String code = OTP.generateTOTPCodeString(
otpObjects[index].secret,
DateTime.now().millisecondsSinceEpoch,
interval: _animationLength,
algorithm: Algorithm.SHA1,
isGoogle: true);