Comments (4)
Hi @melio-matt
Can you please provide some test cases or any screenshots or a video that how are you implementing it and what are you trying to do?
Thanks
Nikhil
from flutter_carousel_widget.
Hi @nixrajput
I've added below some code that illustrates what I'm doing. The floating button when clicked alters the state and removes one of the pages from the carousel. Before pressing this, navigate to the last page and enter some text into the box, then press the button. You will then see the input box no longer has the text present. There is some commented out code that switches out the local and global keys. Once swapped round and you repeat the above action you will see the text is maintained in the input box.
regards
Matthew
import 'package:flutter/material.dart';
import 'package:flutter_carousel_widget/flutter_carousel_widget.dart';
void main() {
runApp(const MyApp());
}
GlobalKey inputScreenGlobalKey = GlobalKey();
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Carousel State Test'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
CarouselController carouselController = CarouselController();
bool _itemsAltered = false;
void _alterItems() {
setState(() {
_itemsAltered = !_itemsAltered;
});
}
@override
Widget build(BuildContext context) {
List<Widget> carouselItems = [];
carouselItems.add(const Text("panel 1", key: ValueKey("panel1")));
if (_itemsAltered == false) {
carouselItems.add(const Text("panel 2", key: ValueKey("panel2")));
}
// swap these lines to move between local keys and global keys
carouselItems.add(const InputScreen(key: ValueKey("inputScreen")));
// carouselItems.add(InputScreen(key: inputScreenGlobalKey));
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: FlutterCarousel(
items: carouselItems,
options: CarouselOptions(),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _alterItems,
tooltip: 'Alter',
child: const Icon(Icons.ac_unit),
),
);
}
}
class InputScreen extends StatefulWidget {
const InputScreen({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _InputScreenState();
}
}
class _InputScreenState extends State<InputScreen> {
late TextEditingController textEditingController;
@override
void initState() {
super.initState();
textEditingController = TextEditingController();
}
@override
Widget build(BuildContext context) {
return TextField(
controller: textEditingController,
);
}
}
```
from flutter_carousel_widget.
Hi @melio-matt
I will look into this and I will definitely revert back to you after testing and solution.
Please have some patience.
Thanks and regards,
Nikhil
from flutter_carousel_widget.
Thanks @nixrajput
No massive urgency, I have a solution that works for me at the moment and will be easy enough to put back in the more permanent solution.
Matthew
from flutter_carousel_widget.
Related Issues (20)
- carouselController is missing from CarouselOptions function definition HOT 1
- how remove 'setState' error log? HOT 2
- set custom slide indicator HOT 1
- [Bug]: [3.7.12] page changed reason is always controller. HOT 1
- [Bug]: Infinite-scrolling carousels get out of sync with their indicators.
- [Feature Request]: Maximum height value HOT 2
- [Feature Request]: Make image transitions smooth HOT 1
- License HOT 2
- [Bug]: Indicator remains half-filled when padEnds: false HOT 1
- Portrait images do not fill the available space on iPad
- [Bug]: it crashes
- Feature: Tap indicator change slider HOT 3
- [Bug]: The original package is not listed in the license. HOT 1
- [Feature Request]: Itens with shadowed borders
- [Feature Request]: Expose SlideIndicator contract
- [Bug]: initialPage parameter should affect the slide indicators HOT 1
- [Feature Request]: Add Test Cases
- A method to know center item
- [Feature Request]: enlargeCenterPage support for ExpandableCarousel
- [Bug]: pinch and zoom HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_carousel_widget.