diff --git a/lib/apis/githost_factory.dart b/lib/apis/githost_factory.dart new file mode 100644 index 00000000..ce3c5794 --- /dev/null +++ b/lib/apis/githost_factory.dart @@ -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; + } +} diff --git a/lib/oauthapp.dart b/lib/oauthapp.dart index 6ddc5d07..22ea45a7 100644 --- a/lib/oauthapp.dart +++ b/lib/oauthapp.dart @@ -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 { 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"); }); }