Skip to content
Snippets Groups Projects
statistics_card.dart 1.41 KiB
Newer Older
  • Learn to ignore specific revisions
  • import 'dart:convert';
    
    import 'package:flutter/material.dart';
    
    import '../../../models/statistics.dart';
    import '../../../network/scrobbles_api.dart';
    import '../../../ui/widgets/error.dart';
    import '../../../ui/widgets/main_screen/statistics_content.dart';
    
    class StatisticsCard extends StatelessWidget {
      const StatisticsCard({super.key});
    
      @override
      Widget build(BuildContext context) {
    
        final int daysCount = 14;
        late Future<StatisticsData> futureStatistics = ScrobblesApi.fetchStatistics(daysCount);
    
    
        return FutureBuilder<StatisticsData>(
    
          future: futureStatistics,
    
          builder: (context, snapshot) {
            if (snapshot.hasError) {
              return ShowErrorWidget(message: '${snapshot.error}');
            }
    
            return Card(
              elevation: 2,
              shadowColor: Theme.of(context).colorScheme.shadow,
              color: Theme.of(context).colorScheme.primary,
              shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(
    
    Benoît Harrault's avatar
    Benoît Harrault committed
                  Radius.circular(8),
    
                ),
              ),
              child: Padding(
    
    Benoît Harrault's avatar
    Benoît Harrault committed
                padding: const EdgeInsets.all(8.0),
    
                child: StatisticsContent(
                  statistics: snapshot.hasData
                      ? StatisticsData.fromJson(jsonDecode(snapshot.data.toString()))
                      : StatisticsData.createEmpty(),
                  isLoading: !snapshot.hasData,
                ),
              ),
            );
          },
        );
      }
    }