mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
Add a GitHost factory
There are probably more idiomatic ways of doing this, but I'm not sure how.
This commit is contained in:
24
lib/apis/githost_factory.dart
Normal file
24
lib/apis/githost_factory.dart
Normal file
@ -0,0 +1,24 @@
|
||||
import 'githost.dart';
|
||||
import 'github.dart';
|
||||
import 'gitlab.dart';
|
||||
|
||||
export 'githost.dart';
|
||||
|
||||
enum GitHostType {
|
||||
GitHub,
|
||||
GitLab,
|
||||
Custom,
|
||||
}
|
||||
|
||||
GitHost createGitHost(GitHostType type) {
|
||||
switch (type) {
|
||||
case GitHostType.GitHub:
|
||||
return new GitHub();
|
||||
|
||||
case GitHostType.GitLab:
|
||||
return new GitLab();
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'apis/githost.dart';
|
||||
import 'apis/github.dart';
|
||||
import 'apis/gitlab.dart';
|
||||
import 'apis/githost_factory.dart';
|
||||
|
||||
class OAuthApp extends StatefulWidget {
|
||||
@override
|
||||
@ -20,14 +18,9 @@ class OAuthAppState extends State<OAuthApp> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (true) {
|
||||
githost = new GitHub();
|
||||
} else {
|
||||
githost = new GitLab();
|
||||
}
|
||||
|
||||
githost = createGitHost(GitHostType.GitHub);
|
||||
githost.init(() {
|
||||
print("GitHub initialized and has access code");
|
||||
print("GitHost initialized and has access code");
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user