Skip to content

Commit

Permalink
fix: make reports tour stateless
Browse files Browse the repository at this point in the history
  • Loading branch information
its-me-abhishek committed Jul 6, 2024
1 parent 0e9c5b5 commit 7becfec
Showing 1 changed file with 121 additions and 147 deletions.
268 changes: 121 additions & 147 deletions lib/app/modules/reports/views/reports_view_taskc.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:taskwarrior/api_service.dart';
import 'package:taskwarrior/app/modules/reports/controllers/reports_controller.dart';
Expand All @@ -9,165 +8,140 @@ import 'package:taskwarrior/app/modules/reports/views/burn_down_weekly_taskc.dar
import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart';
import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart';
import 'package:taskwarrior/app/utils/theme/app_settings.dart';
import 'package:tutorial_coach_mark/tutorial_coach_mark.dart';

class ReportsHomeTaskc extends StatefulWidget {
const ReportsHomeTaskc({
super.key,
});
class ReportsHomeTaskc extends StatelessWidget {
final ReportsController reportsController = ReportsController();
final TaskDatabase taskDatabase = TaskDatabase();

@override
State<ReportsHomeTaskc> createState() => _ReportsHomeTaskcState();
}

class _ReportsHomeTaskcState extends State<ReportsHomeTaskc>
with TickerProviderStateMixin {
late TabController _tabController;
final GlobalKey daily = GlobalKey();
final GlobalKey weekly = GlobalKey();
final GlobalKey monthly = GlobalKey();
ReportsHomeTaskc({super.key});

bool isSaved = false;
late TutorialCoachMark tutorialCoachMark;
late ReportsController reportsController;
int _selectedIndex = 0;
late TaskDatabase taskDatabase;
List<Tasks> allTasks = [];

@override
void initState() {
super.initState();
reportsController = Get.find<ReportsController>();
reportsController.initReportsTour();
reportsController.showReportsTour(context);
_tabController = TabController(length: 3, vsync: this);

// Initialize the database and fetch data
taskDatabase = TaskDatabase();
taskDatabase.open().then((_) {
taskDatabase.fetchTasksFromDatabase().then((tasks) {
setState(() {
allTasks = tasks;
});
});
});
Future<List<Tasks>> fetchTasks() async {
await taskDatabase.open();
return await taskDatabase.fetchTasksFromDatabase();
}

@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height; // Screen height
double height = MediaQuery.of(context).size.height;
reportsController.initReportsTour();
reportsController.showReportsTour(context);
return FutureBuilder<List<Tasks>>(
future: fetchTasks(),
builder: (context, snapshot) {
List<Tasks> allTasks = snapshot.data ?? [];

return Scaffold(
appBar: AppBar(
backgroundColor: TaskWarriorColors.kprimaryBackgroundColor,
title: Text(
'Reports',
style: GoogleFonts.poppins(color: TaskWarriorColors.white),
),
leading: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Icon(
Icons.chevron_left,
color: TaskWarriorColors.white,
),
),
bottom: PreferredSize(
preferredSize: Size.fromHeight(
height * 0.1), // Adjust the preferred height as needed
child: TabBar(
controller: _tabController,
labelColor: TaskWarriorColors.white,
labelStyle: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.medium,
fontSize: TaskWarriorFonts.fontSizeSmall,
return Scaffold(
appBar: AppBar(
backgroundColor: TaskWarriorColors.kprimaryBackgroundColor,
title: Text(
'Reports',
style: GoogleFonts.poppins(color: TaskWarriorColors.white),
),
unselectedLabelStyle: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.light,
),
onTap: (value) {
setState(() {
_selectedIndex = value;
});
},
tabs: <Widget>[
Tab(
key: daily,
icon: const Icon(Icons.schedule),
text: 'Daily',
iconMargin: const EdgeInsets.only(bottom: 0.0),
),
Tab(
key: weekly,
icon: const Icon(Icons.today),
text: 'Weekly',
iconMargin: const EdgeInsets.only(bottom: 0.0),
),
Tab(
key: monthly,
icon: const Icon(Icons.date_range),
text: 'Monthly',
iconMargin: const EdgeInsets.only(bottom: 0.0),
leading: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Icon(
Icons.chevron_left,
color: TaskWarriorColors.white,
),
],
),
),
),
backgroundColor: AppSettings.isDarkMode
? TaskWarriorColors.kprimaryBackgroundColor
: TaskWarriorColors.white,
body: allTasks.isEmpty
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.heart_broken,
color: AppSettings.isDarkMode
? TaskWarriorColors.white
: TaskWarriorColors.black,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'No Task found',
style: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.medium,
fontSize: TaskWarriorFonts.fontSizeSmall,
color: AppSettings.isDarkMode
? TaskWarriorColors.white
: TaskWarriorColors.black,
),
),
],
),
bottom: PreferredSize(
preferredSize: Size.fromHeight(height * 0.1),
child: TabBar(
controller: reportsController.tabController,
labelColor: TaskWarriorColors.white,
labelStyle: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.medium,
fontSize: TaskWarriorFonts.fontSizeSmall,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Add a task to see reports',
style: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.light,
fontSize: TaskWarriorFonts.fontSizeSmall,
color: AppSettings.isDarkMode
? TaskWarriorColors.white
: TaskWarriorColors.black,
),
),
],
unselectedLabelStyle: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.light,
),
],
)
: IndexedStack(
index: _selectedIndex,
children: const [
BurnDownDailyTaskc(),
BurnDownWeeklyTask(),
BurnDownMonthlyTaskc(),
],
onTap: (value) {
reportsController.selectedIndex.value = value;
},
tabs: <Widget>[
Tab(
key: reportsController.daily,
icon: const Icon(Icons.schedule),
text: 'Daily',
iconMargin: const EdgeInsets.only(bottom: 0.0),
),
Tab(
key: reportsController.weekly,
icon: const Icon(Icons.today),
text: 'Weekly',
iconMargin: const EdgeInsets.only(bottom: 0.0),
),
Tab(
key: reportsController.monthly,
icon: const Icon(Icons.date_range),
text: 'Monthly',
iconMargin: const EdgeInsets.only(bottom: 0.0),
),
],
),
),
),
backgroundColor: AppSettings.isDarkMode
? TaskWarriorColors.kprimaryBackgroundColor
: TaskWarriorColors.white,
body: snapshot.connectionState == ConnectionState.waiting
? const Center(child: CircularProgressIndicator())
: allTasks.isEmpty
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.heart_broken,
color: AppSettings.isDarkMode
? TaskWarriorColors.white
: TaskWarriorColors.black,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'No Task found',
style: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.medium,
fontSize: TaskWarriorFonts.fontSizeSmall,
color: AppSettings.isDarkMode
? TaskWarriorColors.white
: TaskWarriorColors.black,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Add a task to see reports',
style: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.light,
fontSize: TaskWarriorFonts.fontSizeSmall,
color: AppSettings.isDarkMode
? TaskWarriorColors.white
: TaskWarriorColors.black,
),
),
],
),
],
)
: IndexedStack(
index: reportsController.selectedIndex.value,
children: const [
BurnDownDailyTaskc(),
BurnDownWeeklyTask(),
BurnDownMonthlyTaskc(),
],
),
);
},
);
}
}

0 comments on commit 7becfec

Please sign in to comment.