Skip to content

Commit

Permalink
Update app
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Aug 4, 2023
1 parent 79101f3 commit f6ce9af
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 42 deletions.
12 changes: 8 additions & 4 deletions example/lib/src/common/widget/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:platform_info/platform_info.dart';
import 'package:spinifyapp/src/common/localization/localization.dart';
import 'package:spinifyapp/src/common/widget/window_scope.dart';
import 'package:spinifyapp/src/feature/authentication/widget/authentication_scope.dart';
Expand All @@ -26,18 +28,20 @@ class App extends StatelessWidget {
theme: View.of(context).platformDispatcher.platformBrightness ==
Brightness.dark
? ThemeData.dark(useMaterial3: true)
: ThemeData.light(
useMaterial3: true), // TODO(plugfox): implement theme
: ThemeData.light(useMaterial3: true),
/* themeMode: ThemeMode.system, */
home: const AuthenticationScope(
signInForm: SignInForm(),
child: ChatScreen(),
),
supportedLocales: Localization.supportedLocales,
locale: const Locale('en', 'US'), // TODO(plugfox): implement locale
locale: Localization.supportedLocales
.firstWhereOrNull((e) => e.languageCode == platform.locale) ??
const Locale('en', 'US'),
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
child: WindowScope(
title: Localization.of(context).title,
/* title: Localization.of(context).title, */
child: child ?? const SizedBox.shrink(),
),
),
Expand Down
54 changes: 27 additions & 27 deletions example/lib/src/common/widget/window_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import 'package:window_manager/window_manager.dart';
class WindowScope extends StatefulWidget {
/// {@macro window_scope}
const WindowScope({
required this.title,
required this.child,
this.title,
super.key,
});

/// Title of the window.
final String title;
final String? title;

/// The widget below this widget in the tree.
final Widget child;
Expand Down Expand Up @@ -93,25 +93,28 @@ class _WindowTitleState extends State<_WindowTitle> with WindowListener {
}

@override
Widget build(BuildContext context) => SizedBox(
height: 24,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onPanStart: (details) => windowManager.startDragging(),
onDoubleTap: null,
/* () async {
Widget build(BuildContext context) {
final title = context.findAncestorWidgetOfExactType<WindowScope>()?.title;
return SizedBox(
height: 24,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onPanStart: (details) => windowManager.startDragging(),
onDoubleTap: null,
/* () async {
bool isMaximized = await windowManager.isMaximized();
if (!isMaximized) {
windowManager.maximize();
} else {
windowManager.unmaximize();
}
}, */
child: Material(
color: Theme.of(context).primaryColor,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
child: Material(
color: Theme.of(context).primaryColor,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
if (title != null)
Builder(
builder: (context) {
final size = MediaQuery.of(context).size;
Expand All @@ -133,11 +136,7 @@ class _WindowTitleState extends State<_WindowTitle> with WindowListener {
),
),
child: Text(
context
.findAncestorWidgetOfExactType<
WindowScope>()
?.title ??
'App',
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
Expand All @@ -150,16 +149,17 @@ class _WindowTitleState extends State<_WindowTitle> with WindowListener {
);
},
),
_WindowButtons$Windows(
isFullScreen: _isFullScreen,
isAlwaysOnTop: _isAlwaysOnTop,
setAlwaysOnTop: setAlwaysOnTop,
),
],
),
_WindowButtons$Windows(
isFullScreen: _isFullScreen,
isAlwaysOnTop: _isAlwaysOnTop,
setAlwaysOnTop: setAlwaysOnTop,
),
],
),
),
);
),
);
}
}

class _WindowButtons$Windows extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,20 @@ class _AuthenticationScopeState extends State<AuthenticationScope> {
Widget build(BuildContext context) => _InheritedAuthenticationScope(
controller: _authenticationController,
user: _user,
/* child: switch (_user) {
UnauthenticatedUser _ => widget.signInForm,
AuthenticatedUser _ => widget.child,
}, */
child: ClipRect(
child: StatefulBuilder(
builder: (context, setState) => Stack(
children: <Widget>[
Positioned.fill(
key: const ValueKey<String>('child'),
child: IgnorePointer(
ignoring: _user.isNotAuthenticated,
child: widget.child,
),
),
if (_showForm)
Positioned.fill(
key: const ValueKey<String>('authentication-form'),
child: IgnorePointer(
ignoring: _user.isAuthenticated,
child: AnimatedOpacity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class _SignInFormState extends State<_SignInForm> {
),
],
),
// TODO(plugfox): generate & copy
SignInTextField(
focusNode: _secretFocusNode,
controller: _secretController,
Expand Down
59 changes: 59 additions & 0 deletions example/lib/src/feature/chat/widget/chat_room.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

/// {@template chat_screen}
/// ChatRoom widget.
/// {@endtemplate}
class ChatRoom extends StatefulWidget {
/// {@macro chat_screen}
const ChatRoom({super.key});

/// The state from the closest instance of this class
/// that encloses the given context, if any.
@internal
static _ChatRoomState? maybeOf(BuildContext context) =>
context.findAncestorStateOfType<_ChatRoomState>();

@override
State<ChatRoom> createState() => _ChatRoomState();
}

/// State for widget ChatRoom.
class _ChatRoomState extends State<ChatRoom> {
/* #region Lifecycle */
@override
void initState() {
super.initState();
// Initial state initialization
}

@override
void didUpdateWidget(ChatRoom oldWidget) {
super.didUpdateWidget(oldWidget);
// Widget configuration changed
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
// The configuration of InheritedWidgets has changed
// Also called after initState but before build
}

@override
void dispose() {
// Permanent removal of a tree stent
super.dispose();
}
/* #endregion */

@override
Widget build(BuildContext context) => ListView.builder(
scrollDirection: Axis.vertical,
reverse: true,
itemCount: 1000,
itemBuilder: (context, index) => ListTile(
title: Text('Item $index'),
),
);
}
37 changes: 30 additions & 7 deletions example/lib/src/feature/chat/widget/chat_screen.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
import 'package:flutter/material.dart';
import 'package:spinifyapp/src/common/controller/state_consumer.dart';
import 'package:spinifyapp/src/common/localization/localization.dart';
import 'package:spinifyapp/src/feature/authentication/controller/authentication_controller.dart';
import 'package:spinifyapp/src/feature/authentication/widget/authentication_scope.dart';
import 'package:spinifyapp/src/feature/chat/widget/chat_room.dart';

/// {@template chat_screen}
/// ChatScreen widget.
/// {@endtemplate}
class ChatScreen extends StatelessWidget {
class ChatScreen extends StatefulWidget {
/// {@macro chat_screen}
const ChatScreen({super.key});

@override
State<ChatScreen> createState() => _ChatScreenState();
}

class _ChatScreenState extends State<ChatScreen> {
late final AuthenticationController authController;

@override
void initState() {
super.initState();
authController = AuthenticationScope.controllerOf(context);
}

@override
Widget build(BuildContext context) {
final authController = AuthenticationScope.controllerOf(context);
return StateConsumer(
controller: authController,
builder: (context, state, _) => Scaffold(
appBar: AppBar(
title: const Text('Chat'),
title: Text(Localization.of(context).title),
centerTitle: true,
automaticallyImplyLeading: false,
/* elevation: 4, */
/* pinned: MediaQuery.of(context).size.height > 600, */
actions: <Widget>[
IconButton(
onPressed: state.user.isNotAuthenticated
? null
: () => authController.signOut(),
onPressed: () =>
AuthenticationScope.controllerOf(context).signOut(),
icon: const Icon(Icons.logout),
),
const SizedBox(width: 16),
],
),
body: const Center(
child: Text('Chat'),
body: AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: state.user.map<Widget>(
authenticated: (user) => const ChatRoom(),
unauthenticated: (_) => const SizedBox.expand(),
),
),
),
);
Expand Down

0 comments on commit f6ce9af

Please sign in to comment.