Giter VIP home page Giter VIP logo

Comments (5)

deven98 avatar deven98 commented on September 22, 2024

Hi @hiusanmaz,

This a peculiar bug, I'll test it out and push a fix in a couple of days.

Thanks for reporting this.

from flutter_chess_board.

deven98 avatar deven98 commented on September 22, 2024

Hi @hiusanmaz, I'm unable to recreate your bug (assuming your bug is the board resetting after you change the board arrows).

Here's a video and code snippet which work for me:

Video:

chessissue480.mov

Code:

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  ChessBoardController controller = ChessBoardController();

  var arrows = [
    BoardArrow(
      from: 'd2',
      to: 'd4',
      //color: Colors.red.withOpacity(0.5),
    ),
    BoardArrow(
      from: 'e7',
      to: 'e5',
      color: Colors.red.withOpacity(0.7),
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Chess Demo'),
      ),
      body: Column(
        children: [
          FlatButton(
            onPressed: () {
              setState(() {
                arrows.add(BoardArrow(from: 'a1', to: 'h7'));
              });
            },
            child: Text('Add Arrow'),
          ),
          Expanded(
            child: Center(
              child: ChessBoard(
                controller: controller,
                boardColor: BoardColor.orange,
                arrows: arrows,
                boardOrientation: PlayerColor.white,
              ),
            ),
          ),
          Expanded(
            child: ValueListenableBuilder<Chess>(
              valueListenable: controller,
              builder: (context, game, _) {
                return Text(
                  controller.getSan().fold(
                        '',
                        (previousValue, element) =>
                            previousValue + '\n' + (element ?? ''),
                      ),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}

Do you think there's anything I might need to know for replicating this bug?
Additionally, are you sure the ChessBoardController isn't being recreated since the board is stored in the controller, not in the board Widget itself?

from flutter_chess_board.

hiulusoy avatar hiulusoy commented on September 22, 2024

Hi @deven98,

My business logic is integrated with the onMove method. When a move done; I should be able to clear the arrows or able to add new ones. Now we can try to create and set onMove method to ChessBoard like

child: ChessBoard(
               controller: controller,
               boardColor: BoardColor.orange,
               arrows: arrows,
               boardOrientation: PlayerColor.white,
               onMove: onMove

             ),
onMove(){
// Clear the current arrows with setState
setState(){
arrows = [];
}
Business Logic etc.
// Let's create a new arrow and show
}

And secondly I checked and found I was creating an instance of my main ChessBoardController in initState method. I changed from this:
image

To this:
image

But the problem is still remaining.

from flutter_chess_board.

deven98 avatar deven98 commented on September 22, 2024

Hey @hiusanmaz,

This doesn't really give me any idea of what's going wrong since the example I provided works fine for me even if I use the onMove callback instead of the button.
Can you give me a full example that I can run directly which has your issue - similar to the one in my comment?

Thanks.

from flutter_chess_board.

hiulusoy avatar hiulusoy commented on September 22, 2024

Hello @deven98,
Firstly let me check my Business Logic again. If I still came with errors, I'm going to provide you a full example.

I just checked my Business Logic and found there were some unnecessary setState methods which causes an error that mentioned before on the Stackoverflow, resets the ChessBoard Widget. So I just wrapped my arrow list and ChessBoard widget with ValueNotifier and It's working as expected.

Thank you for your effort.

from flutter_chess_board.

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.