-
Notifications
You must be signed in to change notification settings - Fork 64
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
Dynamic BoardArrow List #23
Comments
Hi @hiusanmaz, This a peculiar bug, I'll test it out and push a fix in a couple of days. Thanks for reporting this. |
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.movCode: 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? |
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
And secondly I checked and found I was creating an instance of my main ChessBoardController in initState method. I changed from this: But the problem is still remaining. |
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. Thanks. |
Hello @deven98, 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. |
My goal was trying to create a dynamic list of BoardArrow that can be changed at each user move.
The problem is after I use setState with BoardArrow list, the 'ChessBoard' widget is going to be reset with the initial position.
The process were;
Create a list of board arrow
Assign board arrow list the to 'ChessBoard' widget that we're mainly using.
After these steps we have two options which are adding new BoardArrow to the list and show in the 'ChessBoard' widget.
Or we can clear the BoardArrow list after we've shown.
The text was updated successfully, but these errors were encountered: