Skip to content

Instantly share code, notes, and snippets.

@GIfatahTH
Last active June 1, 2020 20:22
Show Gist options
  • Save GIfatahTH/fe8cdb1b7327d626176068b5b30027ed to your computer and use it in GitHub Desktop.
Save GIfatahTH/fe8cdb1b7327d626176068b5b30027ed to your computer and use it in GitHub Desktop.
class _MyListItem extends StatelessWidget {
final Item item;
_MyListItem(this.item, {Key key}) : super(key: key);
//with states_rebuilder you can get the current them without BuildContext
final textTheme = RM.theme.textTheme.headline6;
void _displaySnackBar() {
//with states_rebuilder you can get the active ScaffoldState without
// explicitly using the BuildContext
RM.scaffold.showSnackBar(
SnackBar(
content: Text('error.message'),
),
);
}
@override
Widget build(BuildContext context) {
return Dismissible(
key: Key('${item.id}'),
onDismissed: (_) {
// Get the global CatalogState ReactiveModel
RM.get<CatalogState>().setState(
// Invoke deleteItem
(currentState) => CatalogState.deleteItem(
currentState,
item,
),
onError: (context, error) {
// Display SnackBar
_displaySnackBar();
},
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: LimitedBox(
maxHeight: 48,
child: Row(
children: [
AspectRatio(
aspectRatio: 1,
child: Container(
color: item.color,
),
),
SizedBox(width: 24),
Expanded(
child: Text(item.name, style: textTheme),
),
SizedBox(width: 24),
_AddButton(item: item),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment