Skip to content

Commit 8d9a28f

Browse files
committed
Progress github download assets
1 parent c1cb235 commit 8d9a28f

4 files changed

Lines changed: 58 additions & 28 deletions

File tree

lib/features/personal/personal_git.data.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class GitListRepoData {
1717

1818
bool get isDirectory => type == "dir";
1919

20+
bool get isFile => type == "file";
21+
2022
GitListRepoData({
2123
this.name,
2224
this.path,

lib/features/personal/personal_git_view.dart

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import 'package:sengthaite_blog/features/tool/api/github/github_api.dart';
55
import 'package:sengthaite_blog/shared/app.data.dart';
66

77
class PersonalGitView extends StatefulWidget {
8-
const PersonalGitView({super.key, required this.url, required this.token});
8+
const PersonalGitView({
9+
super.key,
10+
required this.url,
11+
required this.path,
12+
required this.token,
13+
});
914

1015
final String url;
16+
final String path;
1117
final String token;
1218

1319
@override
@@ -19,43 +25,65 @@ class _PersonalGitViewState extends State<PersonalGitView> {
1925

2026
@override
2127
void initState() {
22-
fetchGitContent();
2328
super.initState();
29+
fetchGitContent();
2430
}
2531

2632
void fetchGitContent() async {
33+
if (!mounted) return;
2734
var githubApi = GithubAPI(personalAccessToken: widget.token);
28-
var data = await githubApi.listRepos(url: widget.url);
35+
var data = await githubApi.listRepos(url: "${widget.url}/${widget.path}");
2936
list = GitListRepoData.fromJson(data);
3037
setState(() {});
3138
}
3239

33-
void showGitContentDetail(BuildContext context, String? baseUrl) => Navigator.push(
34-
context,
35-
MaterialPageRoute(
36-
builder: (context) => PersonalGitView(url: baseUrl!, token: widget.token),
37-
fullscreenDialog: true,
38-
),
39-
);
40+
void showGitContentDetail(
41+
BuildContext context,
42+
String baseUrl,
43+
String path,
44+
) => Navigator.push(
45+
context,
46+
MaterialPageRoute(
47+
builder: (context) =>
48+
PersonalGitView(url: baseUrl, path: path, token: widget.token),
49+
fullscreenDialog: true,
50+
),
51+
);
4052

4153
@override
4254
Widget build(BuildContext context) {
4355
return Scaffold(
4456
appBar: AppBar(),
4557
body: list.isEmpty
4658
? Center(child: Text("No content available"))
47-
: GridView.extent(
48-
maxCrossAxisExtent: 150,
49-
shrinkWrap: true,
50-
children: List.generate(list.length, (index) {
51-
var item = list.entries!.elementAt(index);
52-
return Center(
53-
child: IconButton.outlined(
59+
: SingleChildScrollView(
60+
child: Wrap(
61+
spacing: 10,
62+
runSpacing: 10,
63+
alignment: WrapAlignment.spaceEvenly,
64+
children: List.generate(list.length, (index) {
65+
var item = list.entries!.elementAt(index);
66+
return IconButton.outlined(
5467
onPressed: () async {
5568
if (item.isDirectory) {
5669
AppData().isLoading.value = true;
57-
var fullUrl = "${widget.url}/${item.path}";
58-
showGitContentDetail(context, fullUrl);
70+
showGitContentDetail(context, widget.url, item.path!);
71+
AppData().isLoading.value = false;
72+
} else if (item.isFile && item.downloadUrl != null) {
73+
AppData().isLoading.value = true;
74+
// await launchUrl(Uri.parse(item.downloadUrl!));
75+
// var dio = Dio(
76+
// BaseOptions(
77+
// headers: {
78+
// "Accept": "application/vnd.github.v3.raw",
79+
// },
80+
// receiveDataWhenStatusError: true,
81+
// followRedirects: true,
82+
// maxRedirects: 3,
83+
// persistentConnection: true,
84+
// ),
85+
// );
86+
// dio.get
5987
AppData().isLoading.value = false;
6088
}
6189
},
@@ -68,9 +96,9 @@ class _PersonalGitViewState extends State<PersonalGitView> {
6896
),
6997
],
7098
),
71-
),
72-
);
73-
}),
99+
);
100+
}),
101+
),
74102
),
75103
);
76104
}

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class _StateMainView extends State<MainView> {
106106
context,
107107
MaterialPageRoute(
108108
builder: (context) =>
109-
PersonalGitView(url: response['url'], token: response['token']),
109+
PersonalGitView(url: response['url'], path: "", token: response['token']),
110110
fullscreenDialog: true,
111111
),
112112
);

lib/shared/dialog/github_login_dialog.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ class _GithubLoginWidgetState extends State<GithubLoginWidget> {
4141
IconButton.outlined(
4242
onPressed: () async {
4343
String? fileContent = AppData().appSettings?.githubToken;
44-
fileContent ??= await openFilePicker();
45-
if (fileContent == null) {
46-
debugPrint("Invalid file");
47-
return;
48-
}
4944
try {
45+
fileContent ??= await openFilePicker();
46+
if (fileContent == null) {
47+
debugPrint("Invalid file");
48+
return;
49+
}
5050
var jsonData = jsonDecode(fileContent);
5151
var token = jsonData['token'];
5252
var url = jsonData['url'];

0 commit comments

Comments
 (0)