Browse Source

docs(neon): document various neon methods

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/1034/head
Nikolas Rimikis 1 year ago
parent
commit
ef5e1de2db
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 3
      packages/neon/neon/lib/neon.dart
  2. 8
      packages/neon/neon/lib/src/app.dart
  3. 7
      packages/neon/neon/lib/src/platform/android.dart
  4. 7
      packages/neon/neon/lib/src/platform/linux.dart
  5. 31
      packages/neon/neon/lib/src/platform/platform.dart
  6. 91
      packages/neon/neon/lib/src/router.dart
  7. 1
      packages/neon/neon/lib/src/theme/color_scheme.dart
  8. 18
      packages/neon/neon/lib/src/theme/theme.dart

3
packages/neon/neon/lib/neon.dart

@ -20,6 +20,9 @@ import 'package:neon/src/utils/user_agent.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
/// Runs Neon with the given [appImplementations].
///
/// Optionally provide a [theme] to set the default style.
Future<void> runNeon({ Future<void> runNeon({
required final Set<AppImplementation> appImplementations, required final Set<AppImplementation> appImplementations,
required final NeonTheme theme, required final NeonTheme theme,

8
packages/neon/neon/lib/src/app.dart

@ -29,13 +29,21 @@ import 'package:tray_manager/tray_manager.dart' as tray;
import 'package:universal_io/io.dart'; import 'package:universal_io/io.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
/// Main Neon widget.
///
/// Sets up all needed callbacks and creates a new [MaterialApp.router].
/// This widget must be the first in the widget tree.
@internal @internal
class NeonApp extends StatefulWidget { class NeonApp extends StatefulWidget {
/// Creates a new Neon app.
const NeonApp({ const NeonApp({
required this.neonTheme, required this.neonTheme,
super.key, super.key,
}); });
/// The base Neon theme.
///
/// This is used to seed the [AppTheme] used by [MaterialApp.theme].
final NeonTheme neonTheme; final NeonTheme neonTheme;
@override @override

7
packages/neon/neon/lib/src/platform/android.dart

@ -1,13 +1,20 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:neon/src/platform/linux.dart';
import 'package:neon/src/platform/platform.dart'; import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/utils/exceptions.dart'; import 'package:neon/src/utils/exceptions.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
/// Android specific platform information.
///
/// See:
/// * [NeonPlatform] to initialize and acquire an instance
/// * [LinuxNeonPlatform] for the Linux implementation
@immutable @immutable
@internal @internal
class AndroidNeonPlatform implements NeonPlatform { class AndroidNeonPlatform implements NeonPlatform {
/// Creates a new Android Neon platform.
const AndroidNeonPlatform(); const AndroidNeonPlatform();
@override @override

7
packages/neon/neon/lib/src/platform/linux.dart

@ -1,12 +1,19 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:neon/src/platform/android.dart';
import 'package:neon/src/platform/platform.dart'; import 'package:neon/src/platform/platform.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:sqflite_common_ffi/sqflite_ffi.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:universal_io/io.dart'; import 'package:universal_io/io.dart';
/// Linux specific platform information.
///
/// See:
/// * [NeonPlatform] to initialize and acquire an instance
/// * [AndroidNeonPlatform] for the Android implementation
@immutable @immutable
@internal @internal
class LinuxNeonPlatform implements NeonPlatform { class LinuxNeonPlatform implements NeonPlatform {
/// Creates a new Linux Neon platform.
const LinuxNeonPlatform(); const LinuxNeonPlatform();
@override @override

31
packages/neon/neon/lib/src/platform/platform.dart

@ -6,8 +6,15 @@ import 'package:neon/src/platform/linux.dart';
import 'package:universal_io/io.dart'; import 'package:universal_io/io.dart';
/// Implements platform specific functionality and exposes the availability of certain features. /// Implements platform specific functionality and exposes the availability of certain features.
///
/// [NeonPlatform.setup] mus be called and completed before acquiring the [instance].
///
/// See:
/// * [AndroidNeonPlatform] for the Android implementation
/// * [LinuxNeonPlatform] for the Linux implementation
@immutable @immutable
abstract interface class NeonPlatform { abstract interface class NeonPlatform {
/// Initializes the platform with the given mocked [platform].
@visibleForTesting @visibleForTesting
factory NeonPlatform.mocked(final NeonPlatform platform) => _platform = platform; factory NeonPlatform.mocked(final NeonPlatform platform) => _platform = platform;
@ -45,18 +52,39 @@ abstract interface class NeonPlatform {
return _platform!; return _platform!;
} }
/// Whether this platform supports web views.
///
/// The support depends on `https://pub.dev/packages/webview_flutter`.
abstract final bool canUseWebView; abstract final bool canUseWebView;
/// Whether this platform can use quick actions.
///
/// The support depends on `https://pub.dev/packages/quick_actions`.
abstract final bool canUseQuickActions; abstract final bool canUseQuickActions;
/// Whether this platform support system trays.
///
/// The support depends on `https://pub.dev/packages/tray_manager`.
abstract final bool canUseSystemTray; abstract final bool canUseSystemTray;
/// Whether this platform supports managing the window.
///
/// The support depends on `https://pub.dev/packages/window_manager`.
abstract final bool canUseWindowManager; abstract final bool canUseWindowManager;
/// Whether this platform can use the camera.
///
/// The support depends on `https://pub.dev/packages/camera`.
abstract final bool canUseCamera; abstract final bool canUseCamera;
/// Whether this platform can use push notifications.
///
/// The support depends on `https://pub.dev/packages/unifiedpush`.
abstract final bool canUsePushNotifications; abstract final bool canUsePushNotifications;
/// Wether this platform can use native sharing.
///
/// The support depends on `https://pub.dev/packages/share_plus`.
abstract final bool canUseSharing; abstract final bool canUseSharing;
/// Whether this platform should use file dialog. /// Whether this platform should use file dialog.
@ -64,7 +92,10 @@ abstract interface class NeonPlatform {
/// This is needed to compensate lacking support of `https://pub.dev/packages/file_picker`. /// This is needed to compensate lacking support of `https://pub.dev/packages/file_picker`.
abstract final bool shouldUseFileDialog; abstract final bool shouldUseFileDialog;
/// Returns the path to a directory where the application may access top
/// level storage which can also be easily accessed by the user outside of the app.
FutureOr<String> get userAccessibleAppDataPath; FutureOr<String> get userAccessibleAppDataPath;
/// Initializes this platform.
FutureOr<void> init(); FutureOr<void> init();
} }

91
packages/neon/neon/lib/src/router.dart

@ -24,6 +24,7 @@ import 'package:neon/src/utils/stream_listenable.dart';
part 'router.g.dart'; part 'router.g.dart';
/// Internal router for the Neon framework.
@internal @internal
GoRouter buildAppRouter({ GoRouter buildAppRouter({
required final GlobalKey<NavigatorState> navigatorKey, required final GlobalKey<NavigatorState> navigatorKey,
@ -68,12 +69,19 @@ Page<void> _buildErrorPage(final BuildContext context, final GoRouterState state
), ),
); );
/// {@template AppRoutes.AccountSettingsRoute}
/// Route for the [AccountSettingsPage].
/// {@endtemplate}
@immutable @immutable
class AccountSettingsRoute extends GoRouteData { class AccountSettingsRoute extends GoRouteData {
/// {@macro AppRoutes.AccountSettingsRoute}
const AccountSettingsRoute({ const AccountSettingsRoute({
required this.accountID, required this.accountID,
}); });
/// The id of the account to show the settings for.
///
/// Passed to [AccountSettingsPage.account].
final String accountID; final String accountID;
@override @override
@ -88,6 +96,9 @@ class AccountSettingsRoute extends GoRouteData {
} }
} }
/// {@template AppRoutes.HomeRoute}
/// Route for the the [HomePage].
/// {@endtemplate}
@TypedGoRoute<HomeRoute>( @TypedGoRoute<HomeRoute>(
path: '/', path: '/',
name: 'home', name: 'home',
@ -128,6 +139,7 @@ class AccountSettingsRoute extends GoRouteData {
) )
@immutable @immutable
class HomeRoute extends GoRouteData { class HomeRoute extends GoRouteData {
/// {@macro AppRoutes.HomeRoute}
const HomeRoute(); const HomeRoute();
@override @override
@ -139,6 +151,13 @@ class HomeRoute extends GoRouteData {
} }
} }
/// {@template AppRoutes.LoginRoute}
/// Route for the the initial [LoginPage].
///
/// All routes related to the login flow are subroutes of this.
/// All subroutes redirect to subroutes of [HomeRoute] if a at least one
/// account is already logged in and further accounts should be added.
/// {@endtemplate}
@TypedGoRoute<LoginRoute>( @TypedGoRoute<LoginRoute>(
path: '/login', path: '/login',
name: 'login', name: 'login',
@ -159,6 +178,7 @@ class HomeRoute extends GoRouteData {
) )
@immutable @immutable
class LoginRoute extends GoRouteData { class LoginRoute extends GoRouteData {
/// {@macro AppRoutes.LoginRoute}
const LoginRoute(); const LoginRoute();
@override @override
@ -176,12 +196,22 @@ class LoginRoute extends GoRouteData {
} }
} }
/// {@template AppRoutes.LoginFlowRoute}
/// Route for the the [LoginFlowPage].
///
/// Redirects to [_AddAccountFlowRoute] when at least one account is already
/// logged in.
/// {@endtemplate}
@immutable @immutable
class LoginFlowRoute extends GoRouteData { class LoginFlowRoute extends GoRouteData {
/// {@macro AppRoutes.LoginFlowRoute}
const LoginFlowRoute({ const LoginFlowRoute({
required this.serverUrl, required this.serverUrl,
}); });
/// {@template AppRoutes.LoginFlow.serverUrl}
/// The url of the server to initiate the login flow for.
/// {@endtemplate}
final Uri serverUrl; final Uri serverUrl;
@override @override
@ -199,8 +229,15 @@ class LoginFlowRoute extends GoRouteData {
} }
} }
/// {@template AppRoutes.LoginQRcodeRoute}
/// Route for the the [LoginQRcodePage].
///
/// Redirects to [_AddAccountQRcodeRoute] when at least one account is already
/// logged in.
/// {@endtemplate}
@immutable @immutable
class LoginQRcodeRoute extends GoRouteData { class LoginQRcodeRoute extends GoRouteData {
/// {@macro AppRoutes.LoginQRcodeRoute}
const LoginQRcodeRoute(); const LoginQRcodeRoute();
@override @override
@ -218,22 +255,47 @@ class LoginQRcodeRoute extends GoRouteData {
} }
} }
/// {@template AppRoutes.LoginCheckServerStatusRoute}
/// Route for the the [LoginCheckServerStatusPage].
///
/// Redirects to [_AddAccountCheckServerStatusRoute] when at least one account
/// is already logged in.
/// {@endtemplate}
@immutable @immutable
class LoginCheckServerStatusRoute extends GoRouteData { class LoginCheckServerStatusRoute extends GoRouteData {
/// {@macro AppRoutes.LoginCheckServerStatusRoute}
///
/// [loginName] and [password] must both be null.
/// Use [LoginCheckServerStatusRoute.withCredentials] to specify credentials.
const LoginCheckServerStatusRoute({ const LoginCheckServerStatusRoute({
required this.serverUrl, required this.serverUrl,
this.loginName, this.loginName,
this.password, this.password,
}); }) : assert(
loginName == null && password == null,
'loginName and password must be null. Use LoginCheckServerStatusRoute.withCredentials instead.',
);
/// {@macro AppRoutes.LoginCheckServerStatusRoute}
///
/// See [LoginCheckServerStatusRoute] for a route without initial credentials.
const LoginCheckServerStatusRoute.withCredentials({ const LoginCheckServerStatusRoute.withCredentials({
required this.serverUrl, required this.serverUrl,
required String this.loginName, required String this.loginName,
required String this.password, required String this.password,
}) : assert(!kIsWeb, 'Might leak the password to the browser history'); }) : assert(!kIsWeb, 'Might leak the password to the browser history');
/// {@macro AppRoutes.LoginFlow.serverUrl}
final Uri serverUrl; final Uri serverUrl;
/// {@template AppRoutes.LoginFlow.loginName}
/// The login name of the credentials.
/// {@endtemplate}
final String? loginName; final String? loginName;
/// {@template AppRoutes.LoginFlow.password}
/// The password of the credentials.
/// {@endtemplate}
final String? password; final String? password;
@override @override
@ -273,16 +335,28 @@ class LoginCheckServerStatusRoute extends GoRouteData {
} }
} }
/// {@template AppRoutes.LoginCheckAccountRoute}
/// Route for the the [LoginCheckAccountPage].
///
/// Redirects to [_AddAccountCheckAccountRoute] when at least one account
/// is already logged in.
/// {@endtemplate}
@immutable @immutable
class LoginCheckAccountRoute extends GoRouteData { class LoginCheckAccountRoute extends GoRouteData {
/// {@macro AppRoutes.LoginCheckAccountRoute}
const LoginCheckAccountRoute({ const LoginCheckAccountRoute({
required this.serverUrl, required this.serverUrl,
required this.loginName, required this.loginName,
required this.password, required this.password,
}) : assert(!kIsWeb, 'Might leak the password to the browser history'); }) : assert(!kIsWeb, 'Might leak the password to the browser history');
/// {@macro AppRoutes.LoginFlow.serverUrl}
final Uri serverUrl; final Uri serverUrl;
/// {@macro AppRoutes.LoginFlow.loginName}
final String loginName; final String loginName;
/// {@macro AppRoutes.LoginFlow.password}
final String password; final String password;
@override @override
@ -364,12 +438,17 @@ class _AddAccountCheckAccountRoute extends LoginCheckAccountRoute {
String get password => super.password; String get password => super.password;
} }
/// {@template AppRoutes.NextcloudAppSettingsRoute}
/// Route for the the [NextcloudAppSettingsPage].
/// {@endtemplate}
@immutable @immutable
class NextcloudAppSettingsRoute extends GoRouteData { class NextcloudAppSettingsRoute extends GoRouteData {
/// {@macro AppRoutes.NextcloudAppSettingsRoute}
const NextcloudAppSettingsRoute({ const NextcloudAppSettingsRoute({
required this.appid, required this.appid,
}); });
/// The id of the app to display the settings for.
final String appid; final String appid;
@override @override
@ -381,9 +460,15 @@ class NextcloudAppSettingsRoute extends GoRouteData {
} }
} }
/// {@template AppRoutes.SettingsRoute}
/// Route for the the [SettingsPage].
/// {@endtemplate}
@immutable @immutable
class SettingsRoute extends GoRouteData { class SettingsRoute extends GoRouteData {
const SettingsRoute({this.initialCategory}); /// {@macro AppRoutes.SettingsRoute}
const SettingsRoute({
this.initialCategory,
});
/// The initial category to show. /// The initial category to show.
final SettingsCategories? initialCategory; final SettingsCategories? initialCategory;

1
packages/neon/neon/lib/src/theme/color_scheme.dart

@ -5,6 +5,7 @@ import 'package:neon/src/theme/neon.dart';
/// A ColorScheme used in the [NeonTheme]. /// A ColorScheme used in the [NeonTheme].
@immutable @immutable
class NeonColorScheme { class NeonColorScheme {
/// Creates a new Neon color scheme.
const NeonColorScheme({ const NeonColorScheme({
this.primary = NcColors.primary, this.primary = NcColors.primary,
}); });

18
packages/neon/neon/lib/src/theme/theme.dart

@ -5,9 +5,11 @@ import 'package:neon/src/theme/neon.dart';
import 'package:neon/src/utils/hex_color.dart'; import 'package:neon/src/utils/hex_color.dart';
import 'package:nextcloud/core.dart' as core; import 'package:nextcloud/core.dart' as core;
/// Custom theme used for the Neon app.
@internal @internal
@immutable @immutable
class AppTheme { class AppTheme {
/// Creates a new Neon app theme.
const AppTheme( const AppTheme(
this.nextcloudTheme, { this.nextcloudTheme, {
required this.neonTheme, required this.neonTheme,
@ -16,10 +18,19 @@ class AppTheme {
this.appThemes, this.appThemes,
}) : keepOriginalAccentColor = nextcloudTheme == null || keepOriginalAccentColor; }) : keepOriginalAccentColor = nextcloudTheme == null || keepOriginalAccentColor;
/// The theme provided by the Nextcloud server.
final core.ThemingPublicCapabilities_Theming? nextcloudTheme; final core.ThemingPublicCapabilities_Theming? nextcloudTheme;
/// Whether to force the use of the Nextcloud accent color.
final bool keepOriginalAccentColor; final bool keepOriginalAccentColor;
/// Whether to use [NcColors.oledBackground] in the dark theme.
final bool oledAsDark; final bool oledAsDark;
/// The theme extensions provided by the `AppImplementation`s.
final Iterable<ThemeExtension>? appThemes; final Iterable<ThemeExtension>? appThemes;
/// The base theme for the Neon app.
final NeonTheme neonTheme; final NeonTheme neonTheme;
ColorScheme _buildColorScheme(final Brightness brightness) { ColorScheme _buildColorScheme(final Brightness brightness) {
@ -56,7 +67,14 @@ class AppTheme {
); );
} }
/// Returns a new theme for [Brightness.light].
///
/// Used in [MaterialApp.theme].
ThemeData get lightTheme => _getTheme(Brightness.light); ThemeData get lightTheme => _getTheme(Brightness.light);
/// Returns a new theme for [Brightness.dark].
///
/// Used in [MaterialApp.darkTheme].
ThemeData get darkTheme => _getTheme(Brightness.dark); ThemeData get darkTheme => _getTheme(Brightness.dark);
static const _snackBarTheme = SnackBarThemeData( static const _snackBarTheme = SnackBarThemeData(

Loading…
Cancel
Save