Comments (5)
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.
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.
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:
But the problem is still remaining.
from flutter_chess_board.
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.
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)
- onCheckMate not working
- casteling not possible
- onCheckMate not working HOT 2
- Chessboard displays only the white pawn symbol HOT 1
- dart 2 problem! HOT 3
- Null safety HOT 1
- board resets after calling setState() HOT 1
- [Feature Request] Adding arrows to plan moves HOT 2
- Check Event HOT 2
- [Feature Request] Show Available Moves for Each Piece HOT 1
- Small pieces during Drag & Drop in Desktop
- undo Move HOT 3
- castling
- [Feature request] Add next() back() functions in ChessBoardController
- Option to show markings
- makeMove with fedback about success or fail
- Support for UCI
- Doesn't Parse "fancy" PGN
- Deprecated DragTarget Callbacks in Flutter Project
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_chess_board.