mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +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 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'apis/githost.dart';
|
import 'apis/githost_factory.dart';
|
||||||
import 'apis/github.dart';
|
|
||||||
import 'apis/gitlab.dart';
|
|
||||||
|
|
||||||
class OAuthApp extends StatefulWidget {
|
class OAuthApp extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@ -20,14 +18,9 @@ class OAuthAppState extends State<OAuthApp> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
if (true) {
|
githost = createGitHost(GitHostType.GitHub);
|
||||||
githost = new GitHub();
|
|
||||||
} else {
|
|
||||||
githost = new GitLab();
|
|
||||||
}
|
|
||||||
|
|
||||||
githost.init(() {
|
githost.init(() {
|
||||||
print("GitHub initialized and has access code");
|
print("GitHost initialized and has access code");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user