Removed top items entries animation

This commit is contained in:
Juan Gilsanz Polo 2024-01-25 00:50:35 +01:00
parent 2fd829021c
commit a40580f425

View file

@ -8,7 +8,7 @@ import 'package:adguard_home_manager/models/menu_option.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/providers/status_provider.dart'; import 'package:adguard_home_manager/providers/status_provider.dart';
class RowItem extends StatefulWidget { class RowItem extends StatelessWidget {
final HomeTopItems type; final HomeTopItems type;
final Color chartColor; final Color chartColor;
final String domain; final String domain;
@ -32,61 +32,14 @@ class RowItem extends StatefulWidget {
this.unit, this.unit,
}); });
@override
State<RowItem> createState() => _RowItemState();
}
class _RowItemState extends State<RowItem> with TickerProviderStateMixin {
late AnimationController expandController;
late Animation<double> animation;
@override
void initState() {
super.initState();
prepareAnimations();
_runExpandCheck();
}
void prepareAnimations() {
expandController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 250)
);
animation = CurvedAnimation(
parent: expandController,
curve: Curves.ease,
);
}
void _runExpandCheck() {
if (widget.showColor) {
expandController.forward();
}
else {
expandController.reverse();
}
}
@override
void didUpdateWidget(oldWidget) {
super.didUpdateWidget(oldWidget);
_runExpandCheck();
}
@override
void dispose() {
expandController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final statusProvider = Provider.of<StatusProvider>(context); final statusProvider = Provider.of<StatusProvider>(context);
String? name; String? name;
if (widget.clients == true) { if (clients == true) {
try { try {
name = statusProvider.serverStatus!.clients.firstWhere((c) => c.ids.contains(widget.domain)).name; name = statusProvider.serverStatus!.clients.firstWhere((c) => c.ids.contains(domain)).name;
} catch (e) { } catch (e) {
// ---- // // ---- //
} }
@ -95,9 +48,9 @@ class _RowItemState extends State<RowItem> with TickerProviderStateMixin {
return Material( return Material(
color: Colors.transparent, color: Colors.transparent,
child: OptionsMenu( child: OptionsMenu(
value: widget.domain, value: domain,
options: widget.options, options: options,
onTap: widget.onTapEntry, onTap: onTapEntry,
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 20, horizontal: 20,
@ -109,18 +62,13 @@ class _RowItemState extends State<RowItem> with TickerProviderStateMixin {
Flexible( Flexible(
child: Row( child: Row(
children: [ children: [
SizeTransition( Container(
axisAlignment: 1.0, margin: const EdgeInsets.only(right: 16),
sizeFactor: animation, width: 12,
axis: Axis.horizontal, height: 12,
child: Container( decoration: BoxDecoration(
margin: const EdgeInsets.only(right: 16), borderRadius: BorderRadius.circular(30),
width: 12, color: chartColor
height: 12,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: widget.chartColor
),
), ),
), ),
Expanded( Expanded(
@ -128,7 +76,7 @@ class _RowItemState extends State<RowItem> with TickerProviderStateMixin {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
widget.domain, domain,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
@ -154,7 +102,7 @@ class _RowItemState extends State<RowItem> with TickerProviderStateMixin {
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
Text( Text(
widget.number, number,
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.onSurface color: Theme.of(context).colorScheme.onSurface
), ),
@ -167,7 +115,7 @@ class _RowItemState extends State<RowItem> with TickerProviderStateMixin {
} }
} }
class OthersRowItem extends StatefulWidget { class OthersRowItem extends StatelessWidget {
final List<Map<String, dynamic>> items; final List<Map<String, dynamic>> items;
final bool showColor; final bool showColor;
@ -177,111 +125,60 @@ class OthersRowItem extends StatefulWidget {
required this.showColor, required this.showColor,
}); });
@override
State<OthersRowItem> createState() => _OthersRowItemState();
}
class _OthersRowItemState extends State<OthersRowItem> with SingleTickerProviderStateMixin {
late AnimationController expandController;
late Animation<double> animation;
@override
void initState() {
super.initState();
prepareAnimations();
_runExpandCheck();
}
void prepareAnimations() {
expandController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 250)
);
animation = CurvedAnimation(
parent: expandController,
curve: Curves.ease,
);
}
void _runExpandCheck() {
if (widget.showColor) {
expandController.forward();
}
else {
expandController.reverse();
}
}
@override
void didUpdateWidget(oldWidget) {
super.didUpdateWidget(oldWidget);
_runExpandCheck();
}
@override
void dispose() {
expandController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (widget.items.length <= 5) { if (items.length <= 5) {
return const SizedBox(); return const SizedBox();
} }
return SizeTransition( return Padding(
axisAlignment: 1.0, padding: const EdgeInsets.symmetric(
sizeFactor: animation, horizontal: 20,
child: Padding( vertical: 8
padding: const EdgeInsets.symmetric( ),
horizontal: 20, child: Row(
vertical: 8 mainAxisAlignment: MainAxisAlignment.spaceBetween,
), children: [
child: Row( Flexible(
mainAxisAlignment: MainAxisAlignment.spaceBetween, child: Row(
children: [ children: [
Flexible( Container(
child: Row( margin: const EdgeInsets.only(right: 16),
children: [ width: 12,
Container( height: 12,
margin: const EdgeInsets.only(right: 16), decoration: BoxDecoration(
width: 12, borderRadius: BorderRadius.circular(30),
height: 12, color: Colors.grey
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.grey
),
), ),
Expanded( ),
child: Column( Expanded(
crossAxisAlignment: CrossAxisAlignment.start, child: Column(
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Text( children: [
AppLocalizations.of(context)!.others, Text(
overflow: TextOverflow.ellipsis, AppLocalizations.of(context)!.others,
style: TextStyle( overflow: TextOverflow.ellipsis,
fontSize: 16, style: TextStyle(
color: Theme.of(context).colorScheme.onSurface fontSize: 16,
), color: Theme.of(context).colorScheme.onSurface
), ),
], ),
), ],
), ),
], ),
), ],
), ),
const SizedBox(width: 16), ),
Text( const SizedBox(width: 16),
List<int>.from( Text(
widget.items.sublist(5, widget.items.length).map((e) => e.values.first.toInt()) List<int>.from(
).reduce((a, b) => a + b).toString(), items.sublist(5, items.length).map((e) => e.values.first.toInt())
style: TextStyle( ).reduce((a, b) => a + b).toString(),
color: Theme.of(context).colorScheme.onSurface style: TextStyle(
), color: Theme.of(context).colorScheme.onSurface
) ),
], )
), ],
), ),
); );
} }