add data service and homepage data retrieval
This commit is contained in:
58
lib/components/pages/dashboard.dart
Normal file
58
lib/components/pages/dashboard.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mileograph_flutter/services/authservice.dart';
|
||||
import 'package:mileograph_flutter/services/dataService.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class Dashboard extends StatelessWidget {
|
||||
const Dashboard({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = context.watch<DataService>();
|
||||
final auth = context.watch<AuthService>();
|
||||
return DashboardHeader(auth: auth, data: data);
|
||||
}
|
||||
}
|
||||
|
||||
class DashboardHeader extends StatelessWidget {
|
||||
const DashboardHeader({super.key, required this.auth, required this.data});
|
||||
|
||||
final AuthService auth;
|
||||
final DataService data;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
auth.fullName ?? "Unknown",
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(text: "Total Mileage: "),
|
||||
TextSpan(
|
||||
text: data.homepageStats?.totalMileage.toString() ?? "0",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(text: DateTime.now().year.toString()),
|
||||
TextSpan(text: " Mileage: "),
|
||||
TextSpan(text: data.getMileageForCurrentYear().toString()),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user