Skip to content

Commit e91dbc3

Browse files
authored
Merge pull request #299 from zillydev/feature/SelectDataDirectory
Add Select Data Directory Feature
2 parents efb6708 + cf8a915 commit e91dbc3

File tree

10 files changed

+541
-181
lines changed

10 files changed

+541
-181
lines changed

lib/controller/WidgetController.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import 'package:flutter/material.dart';
77
import 'package:flutter/services.dart';
88
import 'package:get/get.dart'; // Import the GetX package
99
import 'package:home_widget/home_widget.dart';
10-
// ignore: depend_on_referenced_packages
11-
import 'package:path_provider/path_provider.dart';
1210
import 'package:syncfusion_flutter_charts/charts.dart';
1311
import 'package:taskwarrior/views/home/home.dart';
1412
import 'package:taskwarrior/widgets/taskdetails/profiles_widget.dart';
@@ -36,7 +34,7 @@ class WidgetController extends GetxController {
3634
storageWidget = StorageWidget.of(context!); // Use Get.context from GetX
3735
var currentProfile = ProfilesWidget.of(context!).currentProfile;
3836

39-
baseDirectory = await getApplicationDocumentsDirectory();
37+
baseDirectory = ProfilesWidget.of(context!).getBaseDirectory();
4038
storage =
4139
Storage(Directory('${baseDirectory!.path}/profiles/$currentProfile'));
4240

@@ -63,7 +61,10 @@ class WidgetController extends GetxController {
6361
}
6462
}
6563
if (l.isEmpty) {
66-
l.add({"description": "No tasks added yet.", "urgency": "urgencyLevel : 0"});
64+
l.add({
65+
"description": "No tasks added yet.",
66+
"urgency": "urgencyLevel : 0"
67+
});
6768
}
6869
await HomeWidget.saveWidgetData('tasks', jsonEncode(l));
6970
}

lib/main.dart

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:get/get.dart';
99
import 'package:loggy/loggy.dart';
1010
import 'package:path_provider/path_provider.dart';
1111
import 'package:permission_handler/permission_handler.dart';
12+
import 'package:shared_preferences/shared_preferences.dart';
1213
import 'package:sizer/sizer.dart';
1314
import 'package:taskwarrior/controller/WidgetController.dart';
1415
import 'package:taskwarrior/controller/onboarding_controller.dart';
@@ -47,21 +48,30 @@ Future main([List<String> args = const []]) async {
4748
'${testingDirectory.path}/profiles/acae0462-6a34-11e4-8001-002590720087',
4849
).createSync(recursive: true);
4950
}
50-
SystemChrome.setPreferredOrientations([
51-
DeviceOrientation.portraitUp,
52-
DeviceOrientation.portraitDown
53-
]).then((value) =>
54-
runApp(
55-
FutureBuilder<Directory>(
56-
future: getApplicationDocumentsDirectory(),
57-
builder: (context, snapshot) => (snapshot.hasData)
58-
? ProfilesWidget(
59-
baseDirectory: testingDirectory ?? snapshot.data!,
60-
child: const MyApp(),
61-
)
62-
: const AppSetupPlaceholder(),
63-
),
64-
));
51+
SystemChrome.setPreferredOrientations(
52+
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown])
53+
.then((value) => runApp(FutureBuilder<List<Directory>>(
54+
future: getDirectories(),
55+
builder: (context, snapshot) {
56+
if (snapshot.hasData) {
57+
return ProfilesWidget(
58+
defaultDirectory: snapshot.data![0],
59+
baseDirectory: testingDirectory ?? snapshot.data![1],
60+
child: const MyApp(),
61+
);
62+
} else {
63+
return const AppSetupPlaceholder();
64+
}
65+
})));
66+
}
67+
68+
Future<List<Directory>> getDirectories() async {
69+
Directory defaultDirectory = await getApplicationDocumentsDirectory();
70+
SharedPreferences prefs = await SharedPreferences.getInstance();
71+
String? directory = prefs.getString('baseDirectory');
72+
Directory baseDirectory =
73+
(directory != null) ? Directory(directory) : defaultDirectory;
74+
return [defaultDirectory, baseDirectory];
6575
}
6676

6777
Future init() async {

lib/views/reports/pages/burndown_daily.dart

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ignore_for_file: depend_on_referenced_packages, prefer_typing_uninitialized_variables
1+
// ignore_for_file: prefer_typing_uninitialized_variables
22

33
import 'package:flutter/material.dart';
44
import 'package:google_fonts/google_fonts.dart';
@@ -15,7 +15,6 @@ import 'package:taskwarrior/utility/utilities.dart';
1515
import 'package:taskwarrior/views/home/home.dart';
1616
import 'package:taskwarrior/views/reports/widgets/commonChartIndicator.dart';
1717
import 'package:taskwarrior/widgets/taskdetails/profiles_widget.dart';
18-
import 'package:path_provider/path_provider.dart';
1918

2019
class BurnDownDaily extends StatefulWidget {
2120
const BurnDownDaily({super.key});
@@ -83,23 +82,21 @@ class _BurnDownDailyState extends State<BurnDownDaily>
8382
storageWidget = StorageWidget.of(context);
8483
var currentProfile = ProfilesWidget.of(context).currentProfile;
8584

86-
getApplicationDocumentsDirectory().then((directory) {
87-
setState(() {
88-
baseDirectory = directory;
89-
storage = Storage(
90-
Directory('${baseDirectory!.path}/profiles/$currentProfile'),
91-
);
92-
});
93-
94-
///fetch all data contains all the tasks
95-
allData = storage.data.allData();
96-
97-
///check if allData is not empty
98-
if (allData.isNotEmpty) {
99-
///sort the data by daily burn down
100-
sortBurnDownDaily();
101-
}
85+
Directory baseDirectory = ProfilesWidget.of(context).getBaseDirectory();
86+
setState(() {
87+
storage = Storage(
88+
Directory('${baseDirectory.path}/profiles/$currentProfile'),
89+
);
10290
});
91+
92+
///fetch all data contains all the tasks
93+
allData = storage.data.allData();
94+
95+
///check if allData is not empty
96+
if (allData.isNotEmpty) {
97+
///sort the data by daily burn down
98+
sortBurnDownDaily();
99+
}
103100
});
104101
}
105102

lib/views/reports/pages/burndown_monthly.dart

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// ignore_for_file: depend_on_referenced_packages, prefer_typing_uninitialized_variables
1+
// ignore_for_file: prefer_typing_uninitialized_variables
22

33
import 'package:flutter/material.dart';
44
import 'package:google_fonts/google_fonts.dart';
55
import 'package:syncfusion_flutter_charts/charts.dart';
6-
import 'package:path_provider/path_provider.dart';
76
import 'package:taskwarrior/config/app_settings.dart';
87
import 'package:taskwarrior/model/chart.dart';
98
import 'dart:io';
@@ -81,23 +80,21 @@ class _BurnDownMonthltState extends State<BurnDownMonthlt>
8180
storageWidget = StorageWidget.of(context);
8281
var currentProfile = ProfilesWidget.of(context).currentProfile;
8382

84-
getApplicationDocumentsDirectory().then((directory) {
85-
setState(() {
86-
baseDirectory = directory;
87-
storage = Storage(
88-
Directory('${baseDirectory!.path}/profiles/$currentProfile'),
89-
);
90-
});
91-
92-
///fetch all data contains all the tasks
93-
allData = storage.data.allData();
94-
95-
///check if allData is not empty
96-
if (allData.isNotEmpty) {
97-
///sort the data by weekly burn down
98-
sortBurnDownMonthly();
99-
}
83+
Directory baseDirectory = ProfilesWidget.of(context).getBaseDirectory();
84+
setState(() {
85+
storage = Storage(
86+
Directory('${baseDirectory.path}/profiles/$currentProfile'),
87+
);
10088
});
89+
90+
///fetch all data contains all the tasks
91+
allData = storage.data.allData();
92+
93+
///check if allData is not empty
94+
if (allData.isNotEmpty) {
95+
///sort the data by weekly burn down
96+
sortBurnDownMonthly();
97+
}
10198
});
10299
}
103100

lib/views/reports/pages/burndown_weekly.dart

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ignore_for_file: depend_on_referenced_packages, prefer_typing_uninitialized_variables
1+
// ignore_for_file: prefer_typing_uninitialized_variables
22

33
import 'package:flutter/material.dart';
44
import 'package:google_fonts/google_fonts.dart';
@@ -15,7 +15,6 @@ import 'package:taskwarrior/utility/utilities.dart';
1515
import 'package:taskwarrior/views/home/home.dart';
1616
import 'package:taskwarrior/views/reports/widgets/commonChartIndicator.dart';
1717
import 'package:taskwarrior/widgets/taskdetails/profiles_widget.dart';
18-
import 'package:path_provider/path_provider.dart';
1918

2019
class BurnDownWeekly extends StatefulWidget {
2120
const BurnDownWeekly({super.key});
@@ -82,23 +81,21 @@ class _BurnDownWeeklyState extends State<BurnDownWeekly>
8281
storageWidget = StorageWidget.of(context);
8382
var currentProfile = ProfilesWidget.of(context).currentProfile;
8483

85-
getApplicationDocumentsDirectory().then((directory) {
86-
setState(() {
87-
baseDirectory = directory;
88-
storage = Storage(
89-
Directory('${baseDirectory!.path}/profiles/$currentProfile'),
90-
);
91-
});
92-
93-
///fetch all data contains all the tasks
94-
allData = storage.data.allData();
95-
96-
///check if allData is not empty
97-
if (allData.isNotEmpty) {
98-
///sort the data by weekly burn down
99-
sortBurnDownWeekLy();
100-
}
84+
Directory baseDirectory = ProfilesWidget.of(context).getBaseDirectory();
85+
setState(() {
86+
storage = Storage(
87+
Directory('${baseDirectory.path}/profiles/$currentProfile'),
88+
);
10189
});
90+
91+
///fetch all data contains all the tasks
92+
allData = storage.data.allData();
93+
94+
///check if allData is not empty
95+
if (allData.isNotEmpty) {
96+
///sort the data by weekly burn down
97+
sortBurnDownWeekLy();
98+
}
10299
});
103100
}
104101

lib/views/reports/reports_home.dart

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ignore_for_file: depend_on_referenced_packages, prefer_typing_uninitialized_variables
1+
// ignore_for_file: prefer_typing_uninitialized_variables
22

33
import 'dart:io';
44

@@ -17,7 +17,6 @@ import 'package:taskwarrior/views/reports/pages/burndown_weekly.dart';
1717
import 'package:taskwarrior/views/reports/reports_tour.dart';
1818
import 'package:taskwarrior/widgets/pallete.dart';
1919
import 'package:taskwarrior/widgets/taskdetails/profiles_widget.dart';
20-
import 'package:path_provider/path_provider.dart';
2120
import 'package:tutorial_coach_mark/tutorial_coach_mark.dart';
2221

2322
class ReportsHome extends StatefulWidget {
@@ -96,17 +95,15 @@ class _ReportsHomeState extends State<ReportsHome>
9695
storageWidget = StorageWidget.of(context);
9796
var currentProfile = ProfilesWidget.of(context).currentProfile;
9897

99-
getApplicationDocumentsDirectory().then((directory) {
100-
setState(() {
101-
baseDirectory = directory;
102-
storage = Storage(
103-
Directory('${baseDirectory!.path}/profiles/$currentProfile'),
104-
);
105-
});
106-
107-
///fetch all data contains all the tasks
108-
allData = storage.data.allData();
98+
Directory baseDirectory = ProfilesWidget.of(context).getBaseDirectory();
99+
setState(() {
100+
storage = Storage(
101+
Directory('${baseDirectory.path}/profiles/$currentProfile'),
102+
);
109103
});
104+
105+
///fetch all data contains all the tasks
106+
allData = storage.data.allData();
110107
});
111108
}
112109

0 commit comments

Comments
 (0)