This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/plugins/spoiler_card.dart

44 lines
1.0 KiB
Dart

import 'package:flutter/material.dart';
class SpoilerCard extends StatefulWidget {
final String title;
final Widget body;
final bool isExpanded;
SpoilerCard({Key key, @required this.title, @required this.body, this.isExpanded: false}) : super(key: key);
@override
_SpoilerCardState createState() => _SpoilerCardState();
}
class _SpoilerCardState extends State<SpoilerCard> {
bool _expanded;
@override
void initState() {
super.initState();
_expanded = widget.isExpanded;
}
@override
Widget build(BuildContext context) {
return Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
title: Text("${widget.title}"),
trailing: Icon(
_expanded ? Icons.arrow_drop_up : Icons.arrow_drop_down,
size: 20,
),
onTap: () => setState((){_expanded = !_expanded;}),
),
_expanded ? widget.body : Container(height: 0,)
],
),
);
}
}