mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-24 16:50:47 +00:00
- Bump all apps to sdk >=3.0.0 <4.0.0 and add flutter_lints + a shared analysis_options.yaml to every app (flutter analyze is now green repo-wide) - Fix real compile errors in firebase_google_authentication and image_editor, plus deprecated APIs (Matrix4, SvgPicture.color, textScaleFactor), missing async 'mounted' guards, and misc lints via dart fix + manual fixes - Align pubspec 'name' with each folder and Android namespace/applicationId with the documented github.nisrulz.* convention - Convert bmi_calculator from a legacy Flutter module to a standard app with a proper android/ scaffold; fix missing android:exported in launcher manifests across 22 apps so all Android builds pass - Untrack generated build files (GeneratedPluginRegistrant, .flutter-plugins-dependencies) and ignore them
66 lines
1.8 KiB
Dart
66 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
import './chart_bar.dart';
|
|
import '../models/transaction.dart';
|
|
|
|
class Chart extends StatelessWidget {
|
|
final List<Transaction> recentTransactions;
|
|
|
|
const Chart(this.recentTransactions, {super.key});
|
|
|
|
List<Map<String, Object>> get groupedTransactionValues {
|
|
return List.generate(7, (index) {
|
|
final weekDay = DateTime.now().subtract(
|
|
Duration(days: index),
|
|
);
|
|
var totalSum = 0.0;
|
|
|
|
for (var i = 0; i < recentTransactions.length; i++) {
|
|
if (recentTransactions[i].date.day == weekDay.day &&
|
|
recentTransactions[i].date.month == weekDay.month &&
|
|
recentTransactions[i].date.year == weekDay.year) {
|
|
totalSum += recentTransactions[i].amount;
|
|
}
|
|
}
|
|
|
|
return {
|
|
'day': DateFormat.E().format(weekDay).substring(0, 1),
|
|
'amount': totalSum,
|
|
};
|
|
}).reversed.toList();
|
|
}
|
|
|
|
double get totalSpending {
|
|
return groupedTransactionValues.fold(0.0, (sum, item) {
|
|
return sum + (item['amount'] as double);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
elevation: 6,
|
|
margin: EdgeInsets.all(20),
|
|
child: Padding(
|
|
padding: EdgeInsets.all(10),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: groupedTransactionValues.map((data) {
|
|
return Flexible(
|
|
fit: FlexFit.tight,
|
|
child: ChartBar(
|
|
data['day'] as String,
|
|
data['amount'] as double,
|
|
totalSpending == 0.0
|
|
? 0.0
|
|
: (data['amount'] as double) / totalSpending,
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|