mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Dart: Give all functions explicit types
It makes the code easier to understand and this way the static type checker will catch bugs for us.
This commit is contained in:
@ -2,8 +2,10 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
typedef OAuthCallback = void Function(GitHostException);
|
||||
|
||||
abstract class GitHost {
|
||||
void init(Function oAuthCallback);
|
||||
void init(OAuthCallback oAuthCallback);
|
||||
Future launchOAuthScreen();
|
||||
|
||||
Future<UserInfo> getUserInfo();
|
||||
|
@ -16,7 +16,7 @@ class GitHub implements GitHost {
|
||||
var _accessCode = "";
|
||||
|
||||
@override
|
||||
void init(Function callback) {
|
||||
void init(OAuthCallback callback) {
|
||||
Future _handleMessages(MethodCall call) async {
|
||||
if (call.method != "onURL") {
|
||||
print("GitHub Unknown Call: " + call.method);
|
||||
|
@ -18,7 +18,7 @@ class GitLab implements GitHost {
|
||||
var _stateOAuth = "";
|
||||
|
||||
@override
|
||||
void init(Function callback) {
|
||||
void init(OAuthCallback callback) {
|
||||
Future _handleMessages(MethodCall call) async {
|
||||
if (call.method != "onURL") {
|
||||
print("GitLab Unknown Call: " + call.method);
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
import 'package:journal/apis/git.dart';
|
||||
import 'package:journal/apis/githost_factory.dart';
|
||||
import 'package:journal/settings.dart';
|
||||
@ -9,7 +10,7 @@ import 'githostsetup_loading.dart';
|
||||
|
||||
class GitHostSetupAutoConfigure extends StatefulWidget {
|
||||
final GitHostType gitHostType;
|
||||
final Function onDone;
|
||||
final Func1<String, void> onDone;
|
||||
|
||||
GitHostSetupAutoConfigure({
|
||||
@required this.gitHostType,
|
||||
|
@ -1,8 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
import 'package:journal/analytics.dart';
|
||||
|
||||
class GitHostSetupButton extends StatelessWidget {
|
||||
final Function onPressed;
|
||||
final Func0<void> onPressed;
|
||||
final String text;
|
||||
final String iconUrl;
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
import 'package:journal/apis/githost_factory.dart';
|
||||
|
||||
import 'githostsetup_button.dart';
|
||||
|
||||
class GitCloneUrlPage extends StatefulWidget {
|
||||
final Function doneFunction;
|
||||
final Func1<String, void> doneFunction;
|
||||
final String initialValue;
|
||||
|
||||
GitCloneUrlPage({
|
||||
@ -96,8 +97,8 @@ class GitCloneUrlPageState extends State<GitCloneUrlPage> {
|
||||
}
|
||||
|
||||
class GitCloneUrlKnownProviderPage extends StatefulWidget {
|
||||
final Function doneFunction;
|
||||
final Function launchCreateUrlPage;
|
||||
final Func1<String, void> doneFunction;
|
||||
final Func0<void> launchCreateUrlPage;
|
||||
final GitHostType gitHostType;
|
||||
final String initialValue;
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
|
||||
import 'githostsetup_button.dart';
|
||||
|
||||
class GitHostSetupFolderPage extends StatelessWidget {
|
||||
final List<String> folders;
|
||||
final Function rootFolderSelected;
|
||||
final Function subFolderSelected;
|
||||
final Func0<void> rootFolderSelected;
|
||||
final Func1<String, void> subFolderSelected;
|
||||
|
||||
GitHostSetupFolderPage({
|
||||
@required this.folders,
|
||||
@ -47,7 +48,7 @@ class GitHostSetupFolderPage extends StatelessWidget {
|
||||
// FIXME: This needs to be made much much prettier!
|
||||
class FolderListWidget extends StatelessWidget {
|
||||
final List<String> folders;
|
||||
final Function onSelected;
|
||||
final Func1<String, void> onSelected;
|
||||
|
||||
FolderListWidget({
|
||||
@required this.folders,
|
||||
|
@ -3,6 +3,7 @@ import 'dart:io';
|
||||
import 'package:dots_indicator/dots_indicator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
import 'package:journal/analytics.dart';
|
||||
import 'package:journal/apis/git.dart';
|
||||
import 'package:journal/apis/githost_factory.dart';
|
||||
@ -18,7 +19,7 @@ import 'githostsetup_folder.dart';
|
||||
import 'githostsetup_sshkey.dart';
|
||||
|
||||
class GitHostSetupScreen extends StatefulWidget {
|
||||
final Function onCompletedFunction;
|
||||
final Func1<String, void> onCompletedFunction;
|
||||
|
||||
GitHostSetupScreen(this.onCompletedFunction);
|
||||
|
||||
@ -471,8 +472,8 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
||||
}
|
||||
|
||||
class GitHostChoicePage extends StatelessWidget {
|
||||
final Function onKnownGitHost;
|
||||
final Function onCustomGitHost;
|
||||
final Func1<GitHostType, void> onKnownGitHost;
|
||||
final Func0<void> onCustomGitHost;
|
||||
|
||||
GitHostChoicePage({
|
||||
@required this.onKnownGitHost,
|
||||
@ -525,7 +526,7 @@ enum GitHostSetupType {
|
||||
}
|
||||
|
||||
class GitHostAutoConfigureChoicePage extends StatelessWidget {
|
||||
final Function onDone;
|
||||
final Func1<GitHostSetupType, void> onDone;
|
||||
|
||||
GitHostAutoConfigureChoicePage({@required this.onDone});
|
||||
|
||||
|
@ -1,16 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
|
||||
import 'githostsetup_button.dart';
|
||||
import 'githostsetup_loading.dart';
|
||||
|
||||
typedef CopyKeyFunction = void Function(BuildContext context);
|
||||
|
||||
class GitHostSetupSshKeyKnownProvider extends StatelessWidget {
|
||||
final Function doneFunction;
|
||||
final CopyKeyFunction copyKeyFunction;
|
||||
final Func0<void> doneFunction;
|
||||
final Func1<BuildContext, void> copyKeyFunction;
|
||||
final String publicKey;
|
||||
|
||||
final Function openDeployKeyPage;
|
||||
final Func0<void> openDeployKeyPage;
|
||||
|
||||
GitHostSetupSshKeyKnownProvider({
|
||||
@required this.doneFunction,
|
||||
@ -83,8 +82,8 @@ class GitHostSetupSshKeyKnownProvider extends StatelessWidget {
|
||||
}
|
||||
|
||||
class GitHostSetupSshKeyUnknownProvider extends StatelessWidget {
|
||||
final Function doneFunction;
|
||||
final CopyKeyFunction copyKeyFunction;
|
||||
final Func0<void> doneFunction;
|
||||
final Func1<BuildContext, void> copyKeyFunction;
|
||||
final String publicKey;
|
||||
|
||||
GitHostSetupSshKeyUnknownProvider({
|
||||
|
@ -1,8 +1,9 @@
|
||||
import 'package:dots_indicator/dots_indicator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
|
||||
class OnBoardingScreen extends StatefulWidget {
|
||||
final Function onCompletedFunction;
|
||||
final Func0<void> onCompletedFunction;
|
||||
|
||||
OnBoardingScreen(this.onCompletedFunction);
|
||||
|
||||
@ -119,7 +120,7 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
||||
}
|
||||
|
||||
class OnBoardingBottomButton extends StatelessWidget {
|
||||
final Function onPressed;
|
||||
final Func0<void> onPressed;
|
||||
final String text;
|
||||
|
||||
OnBoardingBottomButton({
|
||||
|
@ -170,6 +170,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
function_types:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: function_types
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.2"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -22,6 +22,7 @@ dependencies:
|
||||
device_info: ^0.4.0+1
|
||||
flutter_markdown: ^0.2.0
|
||||
flutter_email_sender: ^2.0.2
|
||||
function_types: ^0.0.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: "^0.7.0"
|
||||
|
Reference in New Issue
Block a user