Files
PiliPlus/lib/pages/setting/widgets/normal_item.dart
My-Responsitories 34c5d6812f opt: settings (#977)
2025-08-10 03:05:36 +00:00

66 lines
1.7 KiB
Dart

import 'package:flutter/material.dart';
typedef StringGetter = String Function();
class NormalItem extends StatefulWidget {
final String? title;
final StringGetter? getTitle;
final String? subtitle;
final StringGetter? getSubtitle;
final String? setKey;
final bool? defaultVal;
final ValueChanged<bool>? onChanged;
final bool? needReboot;
final Widget? leading;
final Widget Function()? getTrailing;
final Function? onTap;
final EdgeInsetsGeometry? contentPadding;
final TextStyle? titleStyle;
const NormalItem({
this.title,
this.getTitle,
this.subtitle,
this.getSubtitle,
this.setKey,
this.defaultVal,
this.onChanged,
this.needReboot,
this.leading,
this.getTrailing,
this.onTap,
this.contentPadding,
this.titleStyle,
super.key,
}) : assert(title != null || getTitle != null);
@override
State<NormalItem> createState() => _NormalItemState();
}
class _NormalItemState extends State<NormalItem> {
@override
Widget build(BuildContext context) {
return ListTile(
contentPadding: widget.contentPadding,
onTap: () => widget.onTap?.call(() {
setState(() {});
}),
title: Text(
widget.title ?? widget.getTitle!(),
style: widget.titleStyle ?? Theme.of(context).textTheme.titleMedium!,
),
subtitle: widget.subtitle != null || widget.getSubtitle != null
? Text(
widget.subtitle ?? widget.getSubtitle!(),
style: Theme.of(context).textTheme.labelMedium!.copyWith(
color: Theme.of(context).colorScheme.outline,
),
)
: null,
leading: widget.leading,
trailing: widget.getTrailing?.call(),
);
}
}