New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled Exception: Null check operator used on a null value #6
Comments
Hi @bradintheusa, Please share the detailed code of widget integration and how are you implementing the logic. I would be happy to help you. Thanks. |
I updated the demo https://github.com/bradintheusa/flutter_carousel_widget I'm guessing it's the future builder or just my bad code. |
Yeah, this is not a widget issue. Can you share your output screenshot or error log?? |
its happen because your variable _state is null kindly make the check condition for this |
Agreed, but that's set and managed by the component not the application. Hence the question. |
I have gone through your code and found that you haven't added the That is why this issue I have updated your code now. For your reference, I am adding the updated code here. Thanks. import 'package:flutter/material.dart';
import 'package:flutter_carousel_widget/flutter_carousel_widget.dart';
class NextPrevState extends StatefulWidget {
const NextPrevState({Key? key}) : super(key: key);
@override
State<NextPrevState> createState() => NextPrevStateState();
}
class NextPrevStateState extends State<NextPrevState> {
Future<String>? _value;
final CarouselController _controller = CarouselController();
int _currIndex = 0;
Future<String> getValue() async {
await Future.delayed(const Duration(seconds: 3));
return 'Flutter Devs';
}
@override
void initState() {
super.initState();
setState(() {
_value = getValue();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Image Slider Demo')),
body: Column(
children: [
FutureBuilder<String>(
future: _value,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return Column(
children: [
Text('Current Index: $_currIndex'),
const SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(left: 10),
child: GestureDetector(
onTap: _controller.previousPage,
child: const Icon(
Icons.chevron_left,
size: 50,
color: Colors.black,
),
),
),
Expanded(
child: Align(
alignment: Alignment.center,
child: Text(
snapshot.data!,
))),
Padding(
padding: const EdgeInsets.only(left: 10),
child: GestureDetector(
onTap: _controller.nextPage,
child: const Icon(
Icons.chevron_right,
size: 50,
color: Colors.black,
),
),
),
],
),
FlutterCarousel(
options: CarouselOptions(
showIndicator: true,
autoPlay: false,
slideIndicator: const CircularSlideIndicator(),
onPageChanged: (index, reason) {
setState(() {
_currIndex = index;
});
}),
items: ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
.map((i) {
return Builder(
builder: (BuildContext context) {
return Text(i);
},
);
}).toList(),
carouselController: _controller,
),
],
);
}
return const Text('Loading');
},
)
],
),
);
}
} |
I hope your issue has been resolved, so I am closing this issue for now. You can reopen it if you still have any issues. |
Much appreciated. |
I get an error because state is null in the most recent version.
Any ideas what I'm missing?
I'll post more code if needed.
flutter_carousel_controller.dart
The text was updated successfully, but these errors were encountered: