Add a GitHost factory

There are probably more idiomatic ways of doing this, but I'm not sure
how.
This commit is contained in:
Vishesh Handa
2019-01-25 11:28:38 +01:00
parent ac5c2be05d
commit bfcfa3b449
2 changed files with 27 additions and 10 deletions

View 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;
}
}

View File

@ -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");
});
}