mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-07 05:32:26 -04:00
native device orientation work
This commit is contained in:
parent
debb475bdc
commit
0d888363ff
3 changed files with 141 additions and 118 deletions
182
lib/app.dart
182
lib/app.dart
|
@ -8,6 +8,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:flutter_translate/flutter_translate.dart';
|
import 'package:flutter_translate/flutter_translate.dart';
|
||||||
import 'package:form_builder_validators/form_builder_validators.dart';
|
import 'package:form_builder_validators/form_builder_validators.dart';
|
||||||
|
import 'package:native_device_orientation/native_device_orientation.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:veilid_support/veilid_support.dart';
|
import 'package:veilid_support/veilid_support.dart';
|
||||||
|
|
||||||
|
@ -100,6 +101,94 @@ class VeilidChatApp extends StatelessWidget {
|
||||||
onInvoke: (intent) => _attachDetach(context)),
|
onInvoke: (intent) => _attachDetach(context)),
|
||||||
}, child: Focus(autofocus: true, child: builder(context)))));
|
}, child: Focus(autofocus: true, child: builder(context)))));
|
||||||
|
|
||||||
|
Widget appBuilder(
|
||||||
|
BuildContext context, LocalizationDelegate localizationDelegate) =>
|
||||||
|
ThemeProvider(
|
||||||
|
initTheme: initialThemeData,
|
||||||
|
builder: (context, theme) => LocalizationProvider(
|
||||||
|
state: LocalizationProvider.of(context).state,
|
||||||
|
child: MultiBlocProvider(
|
||||||
|
providers: [
|
||||||
|
BlocProvider<PreferencesCubit>(
|
||||||
|
create: (context) =>
|
||||||
|
PreferencesCubit(PreferencesRepository.instance),
|
||||||
|
),
|
||||||
|
BlocProvider<NotificationsCubit>(
|
||||||
|
create: (context) => NotificationsCubit(
|
||||||
|
const NotificationsState(queue: IList.empty()))),
|
||||||
|
BlocProvider<ConnectionStateCubit>(
|
||||||
|
create: (context) =>
|
||||||
|
ConnectionStateCubit(ProcessorRepository.instance)),
|
||||||
|
BlocProvider<RouterCubit>(
|
||||||
|
create: (context) => RouterCubit(AccountRepository.instance),
|
||||||
|
),
|
||||||
|
BlocProvider<LocalAccountsCubit>(
|
||||||
|
create: (context) =>
|
||||||
|
LocalAccountsCubit(AccountRepository.instance),
|
||||||
|
),
|
||||||
|
BlocProvider<UserLoginsCubit>(
|
||||||
|
create: (context) =>
|
||||||
|
UserLoginsCubit(AccountRepository.instance),
|
||||||
|
),
|
||||||
|
BlocProvider<ActiveLocalAccountCubit>(
|
||||||
|
create: (context) =>
|
||||||
|
ActiveLocalAccountCubit(AccountRepository.instance),
|
||||||
|
),
|
||||||
|
BlocProvider<PerAccountCollectionBlocMapCubit>(
|
||||||
|
create: (context) => PerAccountCollectionBlocMapCubit(
|
||||||
|
accountRepository: AccountRepository.instance,
|
||||||
|
locator: context.read)),
|
||||||
|
],
|
||||||
|
child:
|
||||||
|
BackgroundTicker(child: _buildShortcuts(builder: (context) {
|
||||||
|
final scale = theme.extension<ScaleScheme>()!;
|
||||||
|
final scaleConfig = theme.extension<ScaleConfig>()!;
|
||||||
|
|
||||||
|
final gradient = LinearGradient(
|
||||||
|
begin: Alignment.topLeft,
|
||||||
|
end: Alignment.bottomRight,
|
||||||
|
colors: scaleConfig.preferBorders &&
|
||||||
|
theme.brightness == Brightness.light
|
||||||
|
? [
|
||||||
|
scale.grayScale.hoverElementBackground,
|
||||||
|
scale.grayScale.subtleBackground,
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
scale.primaryScale.hoverElementBackground,
|
||||||
|
scale.primaryScale.subtleBackground,
|
||||||
|
]);
|
||||||
|
|
||||||
|
final wallpaper = PreferencesRepository
|
||||||
|
.instance.value.themePreference
|
||||||
|
.wallpaper();
|
||||||
|
|
||||||
|
return Stack(
|
||||||
|
fit: StackFit.expand,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
wallpaper ??
|
||||||
|
DecoratedBox(
|
||||||
|
decoration: BoxDecoration(gradient: gradient)),
|
||||||
|
MaterialApp.router(
|
||||||
|
scrollBehavior: const ScrollBehaviorModified(),
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
|
routerConfig: context.read<RouterCubit>().router(),
|
||||||
|
title: translate('app.title'),
|
||||||
|
theme: theme,
|
||||||
|
localizationsDelegates: [
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
FormBuilderLocalizations.delegate,
|
||||||
|
localizationDelegate
|
||||||
|
],
|
||||||
|
supportedLocales: localizationDelegate.supportedLocales,
|
||||||
|
locale: localizationDelegate.currentLocale,
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
})),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => FutureProvider<VeilidChatGlobalInit?>(
|
Widget build(BuildContext context) => FutureProvider<VeilidChatGlobalInit?>(
|
||||||
initialData: null,
|
initialData: null,
|
||||||
|
@ -112,93 +201,14 @@ class VeilidChatApp extends StatelessWidget {
|
||||||
}
|
}
|
||||||
// Once init is done, we proceed with the app
|
// Once init is done, we proceed with the app
|
||||||
final localizationDelegate = LocalizedApp.of(context).delegate;
|
final localizationDelegate = LocalizedApp.of(context).delegate;
|
||||||
return ThemeProvider(
|
|
||||||
initTheme: initialThemeData,
|
|
||||||
builder: (context, theme) => LocalizationProvider(
|
|
||||||
state: LocalizationProvider.of(context).state,
|
|
||||||
child: MultiBlocProvider(
|
|
||||||
providers: [
|
|
||||||
BlocProvider<PreferencesCubit>(
|
|
||||||
create: (context) =>
|
|
||||||
PreferencesCubit(PreferencesRepository.instance),
|
|
||||||
),
|
|
||||||
BlocProvider<NotificationsCubit>(
|
|
||||||
create: (context) => NotificationsCubit(
|
|
||||||
const NotificationsState(queue: IList.empty()))),
|
|
||||||
BlocProvider<ConnectionStateCubit>(
|
|
||||||
create: (context) =>
|
|
||||||
ConnectionStateCubit(ProcessorRepository.instance)),
|
|
||||||
BlocProvider<RouterCubit>(
|
|
||||||
create: (context) =>
|
|
||||||
RouterCubit(AccountRepository.instance),
|
|
||||||
),
|
|
||||||
BlocProvider<LocalAccountsCubit>(
|
|
||||||
create: (context) =>
|
|
||||||
LocalAccountsCubit(AccountRepository.instance),
|
|
||||||
),
|
|
||||||
BlocProvider<UserLoginsCubit>(
|
|
||||||
create: (context) =>
|
|
||||||
UserLoginsCubit(AccountRepository.instance),
|
|
||||||
),
|
|
||||||
BlocProvider<ActiveLocalAccountCubit>(
|
|
||||||
create: (context) =>
|
|
||||||
ActiveLocalAccountCubit(AccountRepository.instance),
|
|
||||||
),
|
|
||||||
BlocProvider<PerAccountCollectionBlocMapCubit>(
|
|
||||||
create: (context) => PerAccountCollectionBlocMapCubit(
|
|
||||||
accountRepository: AccountRepository.instance,
|
|
||||||
locator: context.read)),
|
|
||||||
],
|
|
||||||
child:
|
|
||||||
BackgroundTicker(child: _buildShortcuts(builder: (context) {
|
|
||||||
final scale = theme.extension<ScaleScheme>()!;
|
|
||||||
final scaleConfig = theme.extension<ScaleConfig>()!;
|
|
||||||
|
|
||||||
final gradient = LinearGradient(
|
if (isiOS || isAndroid) {
|
||||||
begin: Alignment.topLeft,
|
return NativeDeviceOrientationReader(
|
||||||
end: Alignment.bottomRight,
|
//useSensor: false,
|
||||||
colors: scaleConfig.preferBorders &&
|
builder: (context) => appBuilder(context, localizationDelegate));
|
||||||
theme.brightness == Brightness.light
|
} else {
|
||||||
? [
|
return appBuilder(context, localizationDelegate);
|
||||||
scale.grayScale.hoverElementBackground,
|
}
|
||||||
scale.grayScale.subtleBackground,
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
scale.primaryScale.hoverElementBackground,
|
|
||||||
scale.primaryScale.subtleBackground,
|
|
||||||
]);
|
|
||||||
|
|
||||||
final wallpaper = PreferencesRepository
|
|
||||||
.instance.value.themePreference
|
|
||||||
.wallpaper();
|
|
||||||
|
|
||||||
return Stack(
|
|
||||||
fit: StackFit.expand,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
children: [
|
|
||||||
wallpaper ??
|
|
||||||
DecoratedBox(
|
|
||||||
decoration: BoxDecoration(gradient: gradient)),
|
|
||||||
MaterialApp.router(
|
|
||||||
scrollBehavior: const ScrollBehaviorModified(),
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
routerConfig: context.read<RouterCubit>().router(),
|
|
||||||
title: translate('app.title'),
|
|
||||||
theme: theme,
|
|
||||||
localizationsDelegates: [
|
|
||||||
GlobalMaterialLocalizations.delegate,
|
|
||||||
GlobalWidgetsLocalizations.delegate,
|
|
||||||
FormBuilderLocalizations.delegate,
|
|
||||||
localizationDelegate
|
|
||||||
],
|
|
||||||
supportedLocales:
|
|
||||||
localizationDelegate.supportedLocales,
|
|
||||||
locale: localizationDelegate.currentLocale,
|
|
||||||
)
|
|
||||||
]);
|
|
||||||
})),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -318,7 +318,7 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
||||||
scale.subtleBorder,
|
scale.subtleBorder,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return DecoratedBox(
|
Widget menu = DecoratedBox(
|
||||||
decoration: ShapeDecoration(
|
decoration: ShapeDecoration(
|
||||||
shadows: themedShadow(scaleConfig, scale),
|
shadows: themedShadow(scaleConfig, scale),
|
||||||
gradient: scaleConfig.useVisualIndicators ? null : gradient,
|
gradient: scaleConfig.useVisualIndicators ? null : gradient,
|
||||||
|
@ -393,6 +393,12 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
]).paddingAll(16),
|
]).paddingAll(16),
|
||||||
).paddingLTRB(0, 2, 2, 2);
|
);
|
||||||
|
|
||||||
|
if (scaleConfig.preferBorders || scaleConfig.useVisualIndicators) {
|
||||||
|
menu = menu.paddingLTRB(0, 2, 2, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return menu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import 'package:veilid_support/veilid_support.dart';
|
||||||
import '../../account_manager/account_manager.dart';
|
import '../../account_manager/account_manager.dart';
|
||||||
import '../../settings/settings.dart';
|
import '../../settings/settings.dart';
|
||||||
import '../../theme/theme.dart';
|
import '../../theme/theme.dart';
|
||||||
|
import '../../tools/native_safe_area.dart';
|
||||||
import 'drawer_menu/drawer_menu.dart';
|
import 'drawer_menu/drawer_menu.dart';
|
||||||
import 'home_account_invalid.dart';
|
import 'home_account_invalid.dart';
|
||||||
import 'home_account_locked.dart';
|
import 'home_account_locked.dart';
|
||||||
|
@ -208,36 +209,42 @@ class HomeScreenState extends State<HomeScreen>
|
||||||
.indexWhere((x) => x.superIdentity.recordKey == activeLocalAccount);
|
.indexWhere((x) => x.superIdentity.recordKey == activeLocalAccount);
|
||||||
final canClose = activeIndex != -1;
|
final canClose = activeIndex != -1;
|
||||||
|
|
||||||
return SafeArea(
|
Widget homeWidget = DefaultTextStyle(
|
||||||
child: DefaultTextStyle(
|
style: theme.textTheme.bodySmall!,
|
||||||
style: theme.textTheme.bodySmall!,
|
child: ZoomDrawer(
|
||||||
child: ZoomDrawer(
|
controller: _zoomDrawerController,
|
||||||
controller: _zoomDrawerController,
|
menuScreen: Builder(builder: (context) {
|
||||||
menuScreen: Builder(builder: (context) {
|
final zoomDrawer = ZoomDrawer.of(context);
|
||||||
final zoomDrawer = ZoomDrawer.of(context);
|
zoomDrawer!.stateNotifier.addListener(() {
|
||||||
zoomDrawer!.stateNotifier.addListener(() {
|
if (zoomDrawer.isOpen()) {
|
||||||
if (zoomDrawer.isOpen()) {
|
FocusManager.instance.primaryFocus?.unfocus();
|
||||||
FocusManager.instance.primaryFocus?.unfocus();
|
}
|
||||||
}
|
});
|
||||||
});
|
return const DrawerMenu();
|
||||||
return const DrawerMenu();
|
}),
|
||||||
}),
|
mainScreen: Provider<ZoomDrawerController>.value(
|
||||||
mainScreen: Provider<ZoomDrawerController>.value(
|
value: _zoomDrawerController,
|
||||||
value: _zoomDrawerController,
|
child: Builder(builder: _buildAccountPageView)),
|
||||||
child: Builder(builder: _buildAccountPageView)),
|
borderRadius: 0,
|
||||||
borderRadius: 0,
|
angle: 0,
|
||||||
angle: 0,
|
//mainScreenOverlayColor: theme.shadowColor.withAlpha(0x2F),
|
||||||
//mainScreenOverlayColor: theme.shadowColor.withAlpha(0x2F),
|
openCurve: Curves.fastEaseInToSlowEaseOut,
|
||||||
openCurve: Curves.fastEaseInToSlowEaseOut,
|
closeCurve: Curves.fastEaseInToSlowEaseOut,
|
||||||
closeCurve: Curves.fastEaseInToSlowEaseOut,
|
// duration: const Duration(milliseconds: 250),
|
||||||
// duration: const Duration(milliseconds: 250),
|
// reverseDuration: const Duration(milliseconds: 250),
|
||||||
// reverseDuration: const Duration(milliseconds: 250),
|
menuScreenTapClose: canClose,
|
||||||
menuScreenTapClose: canClose,
|
mainScreenTapClose: canClose,
|
||||||
mainScreenTapClose: canClose,
|
disableDragGesture: !canClose,
|
||||||
disableDragGesture: !canClose,
|
mainScreenScale: .25,
|
||||||
mainScreenScale: .25,
|
slideWidth: min(360, MediaQuery.of(context).size.width * 0.9),
|
||||||
slideWidth: min(360, MediaQuery.of(context).size.width * 0.9),
|
));
|
||||||
)));
|
|
||||||
|
if (isiOS || isAndroid) {
|
||||||
|
homeWidget = NativeSafeArea(
|
||||||
|
bottom: false, left: false, right: false, child: homeWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
return homeWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue