Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
onTime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
onTime InnoLab
onTime
Commits
3b67b531
Commit
3b67b531
authored
1 month ago
by
Theo Wiese
Browse files
Options
Downloads
Patches
Plain Diff
Replace dart:io with http
parent
16a9792f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pages/home_page.dart
+1
-2
1 addition, 2 deletions
lib/pages/home_page.dart
lib/untis/fetch.dart
+23
-11
23 additions, 11 deletions
lib/untis/fetch.dart
with
24 additions
and
13 deletions
lib/pages/home_page.dart
+
1
−
2
View file @
3b67b531
import
'dart:async'
;
import
'dart:async'
;
import
'dart:io'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
...
@@ -48,7 +47,7 @@ class _HomePageState extends State<HomePage> {
...
@@ -48,7 +47,7 @@ class _HomePageState extends State<HomePage> {
}
}
void
_showErrorDialog
(
String
title
,
Object
?
error
)
{
void
_showErrorDialog
(
String
title
,
Object
?
error
)
{
stderr
.
write
(
error
);
print
(
error
);
showDialog
(
showDialog
(
context:
context
,
context:
context
,
builder:
(
context
)
=
>
ErrorDialog
(
title:
title
,
error:
error
),
builder:
(
context
)
=
>
ErrorDialog
(
title:
title
,
error:
error
),
...
...
This diff is collapsed.
Click to expand it.
lib/untis/fetch.dart
+
23
−
11
View file @
3b67b531
import
'dart:convert'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:http/http.dart'
as
http
;
import
'../fetching/pageconfig.dart'
;
import
'../fetching/pageconfig.dart'
;
import
'../fetching/timetable.dart'
;
import
'../fetching/timetable.dart'
;
import
'../util/date_extension.dart'
;
import
'../util/date_extension.dart'
;
import
'class.dart'
;
import
'../util/serializable.dart'
;
import
'../util/serializable.dart'
;
import
'class.dart'
;
import
'element_type.dart'
;
import
'element_type.dart'
;
import
'lecture.dart'
;
import
'lecture.dart'
;
typedef
Cookie
=
(
String
key
,
String
value
);
typedef
RequestOptions
=
(
String
path
,
String
method
,
Json
params
);
typedef
RequestOptions
=
(
String
path
,
String
method
,
Json
params
);
typedef
RequestResult
=
(
Json
json
,
List
<
Cookie
>
cookies
,
FetchStats
stats
);
typedef
RequestResult
=
(
Json
json
,
List
<
Cookie
>
cookies
,
FetchStats
stats
);
...
@@ -22,7 +24,7 @@ class UntisFetch {
...
@@ -22,7 +24,7 @@ class UntisFetch {
'traceId'
,
'traceId'
,
};
};
final
H
ttpClient
client
=
H
ttpClient
();
final
h
ttp
.
Client
client
=
h
ttp
.
Client
();
final
Uri
serverHost
=
Uri
.
https
(
'poly.webuntis.com'
);
final
Uri
serverHost
=
Uri
.
https
(
'poly.webuntis.com'
);
final
List
<
Cookie
>
_sessionCookies
=
[];
final
List
<
Cookie
>
_sessionCookies
=
[];
...
@@ -63,12 +65,17 @@ class UntisFetch {
...
@@ -63,12 +65,17 @@ class UntisFetch {
);
);
}
}
Future
<
HttpClientResponse
>
_request
(
String
method
,
Uri
uri
)
async
{
Future
<
http
.
StreamedResponse
>
_request
(
String
method
,
Uri
uri
)
async
{
final
request
=
await
client
.
openUrl
(
method
,
uri
);
final
request
=
http
.
Request
(
method
,
uri
);
request
.
cookies
.
add
(
Cookie
(
'schoolname'
,
idHsReutlingen
));
request
.
cookies
.
addAll
(
_sessionCookies
);
final
cookies
=
<
Cookie
>[];
final
response
=
await
request
.
close
();
cookies
.
add
((
'schoolname'
,
idHsReutlingen
));
cookies
.
addAll
(
_sessionCookies
);
request
.
headers
[
'Set-Cookie'
]
=
cookies
.
map
((
cookie
)
=
>
'
${cookie.$1}
=
${cookie.$2}
'
)
.
join
(
'; '
);
final
response
=
await
client
.
send
(
request
);
return
response
;
return
response
;
}
}
...
@@ -78,18 +85,23 @@ class UntisFetch {
...
@@ -78,18 +85,23 @@ class UntisFetch {
final
onStart
=
DateTime
.
now
();
final
onStart
=
DateTime
.
now
();
final
response
=
await
_request
(
method
,
_makeUri
(
options
));
final
response
=
await
_request
(
method
,
_makeUri
(
options
));
final
cookies
=
response
.
cookies
;
final
cookieStrings
=
response
.
headersSplitValues
[
'Set-Cookie'
]
??
<
String
>[];
final
cookies
=
cookieStrings
.
map
((
cookieString
)
=
>
cookieString
.
split
(
'='
))
.
map
<
Cookie
>((
parts
)
=
>
(
parts
[
0
],
parts
[
1
]));
final
resultCookies
=
<
Cookie
>[];
final
resultCookies
=
<
Cookie
>[];
for
(
final
cookie
in
cookies
)
{
for
(
final
cookie
in
cookies
)
{
if
(
_sessionCookieNames
.
contains
(
cookie
.
name
))
{
if
(
_sessionCookieNames
.
contains
(
cookie
.
$
1
))
{
resultCookies
.
add
(
cookie
);
resultCookies
.
add
(
cookie
);
}
}
}
}
final
onDownloadStart
=
DateTime
.
now
();
final
onDownloadStart
=
DateTime
.
now
();
final
responseString
=
await
utf8
.
decodeStream
(
response
);
final
responseString
=
await
utf8
.
decodeStream
(
response
.
stream
);
final
onDownloadEnd
=
DateTime
.
now
();
final
onDownloadEnd
=
DateTime
.
now
();
if
(
response
.
statusCode
!=
200
)
{
if
(
response
.
statusCode
!=
200
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment