GithubHelp home page GithubHelp logo

Comments (4)

nixrajput avatar nixrajput commented on May 27, 2024

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.

melio-matt avatar melio-matt commented on May 27, 2024

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.

nixrajput avatar nixrajput commented on May 27, 2024

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.

melio-matt avatar melio-matt commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.