While creating a simple demo of getx, I am getting an error 'null check operator is used on a null value'
I am using GetBuilder
here is my code
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Getx With Hive'),),
body:GetBuilder<TransactionController>(builder: (controller) {
return ListView.builder(
itemCount: controller.transactions.length,
itemBuilder: (context,index){
return Text('hello');
});
},),
floatingActionButton: FloatingActionButton(
onPressed: (){},
child: Text(' '),
),
);
}
}
CodePudding user response:
just you need to initialize your controller to init properties
add this line in your code init: TransactionController(),
GetBuilder<TransactionController>(
init: TransactionController(),
builder: (controller) {
return ListView.builder(
itemCount: controller.transactions.length,
itemBuilder: (context, index) {
return Text('hello');
});
},
),