TListTheme.defaultTheme constructor

TListTheme.defaultTheme(
  1. ColorScheme colors
)

Creates a default theme derived from the context colors.

Implementation

factory TListTheme.defaultTheme(ColorScheme colors) {
  return TListTheme(
    loadingBuilder: (BuildContext context) {
      return SizedBox(
        height: 4,
        child: LinearProgressIndicator(
          backgroundColor: colors.primaryContainer,
          valueColor: AlwaysStoppedAnimation<Color>(colors.primary),
        ),
      );
    },
    infiniteScrollFooterBuilder: (BuildContext context) {
      final controller = TListScope.maybeOf(context)?.controller;
      final showLoading = controller != null ? controller.listItems.isNotEmpty && controller.isLoading : false;
      final showNoMoreItems = controller != null ? controller.page > 1 && !controller.hasMoreItems : false;

      if (showLoading) {
        return Container(
          padding: const EdgeInsets.all(16.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            spacing: 14,
            children: [
              SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: colors.primary)),
              Text('Loading...', style: TextStyle(fontSize: 14, color: colors.onSurfaceVariant)),
            ],
          ),
        );
      }

      if (showNoMoreItems) {
        return Padding(
          padding: const EdgeInsets.all(16.0),
          child: Text('No more items to display.',
              style: TextStyle(fontSize: 14, color: colors.onSurfaceVariant), textAlign: TextAlign.center),
        );
      }

      return const SizedBox(height: 40);
    },
    dragProxyDecorator: (Widget child, int index, Animation<double> animation) {
      return AnimatedBuilder(
        animation: animation,
        builder: (BuildContext context, Widget? child) {
          final animValue = Curves.easeInOut.transform(animation.value);
          final elevation = lerpDouble(0, 8, animValue) ?? 0;
          final scale = lerpDouble(1.0, 1.01, animValue) ?? 1.0;

          return Transform.scale(
            scale: scale,
            child: Material(
              elevation: elevation,
              color: Colors.transparent,
              shadowColor: context.colors.shadow,
              borderRadius: BorderRadius.circular(8),
              child: child,
            ),
          );
        },
        child: child,
      );
    },
  );
}