Skip to content

Instantly share code, notes, and snippets.

@gisborne
Created April 8, 2019 02:35
Show Gist options
  • Save gisborne/7ae79ff63df4683f713e59ca19a37a88 to your computer and use it in GitHub Desktop.
Save gisborne/7ae79ff63df4683f713e59ca19a37a88 to your computer and use it in GitHub Desktop.
Why can't I access the rebuild() method from the state object?
import 'package:flutter/material.dart';
import 'dice_button.dart';
import 'dice_rack.dart';
import 'dart:developer';
class DiceRow extends StatefulWidget {
final _RowState content = _RowState();
final RackState rack;
DiceRow(this.rack);
bool empty() => content.empty();
void rebuild() {
rack.rebuild();
}
@override
_RowState createState() => content;
}
class _RowState<DiceRow> extends State {
List<DieWidget> _dice = [];
bool empty() => _dice.length == 0;
@override
Widget build(BuildContext context) {
return Container(
height: 80,
decoration: BoxDecoration(
border: Border.all(
color: Colors.green,
width: 5.0,
style: BorderStyle.solid
),
),
child: _rowContent(),
);
}
_rowContent([Widget dropped]) {
if (dropped != null)
_dice.add(dropped);
return DragTarget<DiceDragInfo>(
onWillAccept: (data) => true,
onAccept: (data) {
setState(() => _dice.add(
DieWidget(
data.sides,
data.displayAs,
DraggableDieState(
data.sides,
data.displayAs
)
)
));
debugger();
widget.rebuild();
},
builder: (context, data, rejected_data) {
return Row(
mainAxisSize: MainAxisSize.max,
children: [
IconButton(
icon: Icon(Icons.refresh),
tooltip: 'Reroll',
onPressed: _rollAll,
),
ListView(
shrinkWrap: true,
children: _dice + [],
scrollDirection: Axis.horizontal,
)
]
);
}
);
}
_rollAll() {
setState(() {
_dice.forEach((die) {
die.recalc();
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment