Closed bradintheusa closed 2 years ago
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. @nixrajput
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??
Here, is this what you need.
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.
Hi @bradintheusa
I have gone through your code and found that you haven't added the CarouselController
in FlutterCarousel
.
That is why this issue Null State
is coming.
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