Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/commands/app/update_user_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_folio/data/app_user.dart';

class UpdateUserCommand extends BaseAppCommand {
Future<void> run(AppUser user) async {
if (appModel.currentUser == null) return;
appModel.currentUser = user;
await firebase.setUserData(user);
}
Expand Down
10 changes: 7 additions & 3 deletions lib/styled_widgets/buttons/styled_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,20 @@ class SimpleBtn extends StatelessWidget {

/// Text Btn - wraps a [SimpleBtn]
class TextBtn extends StatelessWidget {
const TextBtn(this.label, {Key key, @required this.onPressed, this.isCompact = false, this.style}) : super(key: key);
const TextBtn(this.label,
{Key key, @required this.onPressed, this.isCompact = false, this.style, this.showUnderline = false})
: super(key: key);
final String label;
final VoidCallback onPressed;
final bool isCompact;
final TextStyle style;
final bool showUnderline;

@override
Widget build(BuildContext context) {
TextStyle finalStyle =
style ?? TextStyles.caption.copyWith(decoration: TextDecoration.underline, fontWeight: FontWeight.w500);
TextStyle finalStyle = style ??
TextStyles.caption.copyWith(
decoration: showUnderline ? TextDecoration.underline : TextDecoration.none, fontWeight: FontWeight.w500);
bool enableTouchMode = context.select((AppModel m) => m.enableTouchMode);
int extraPadding = enableTouchMode ? 3 : 0;
return SimpleBtn(
Expand Down
5 changes: 4 additions & 1 deletion lib/styled_widgets/context_menus/book_context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BookContextMenu extends BaseContextMenu {

@override
Widget build(BuildContext context) {
AppTheme theme = context.watch();
return ContextMenuCard(
children: [
ContextMenuBtn("View",
Expand All @@ -29,7 +30,9 @@ class BookContextMenu extends BaseContextMenu {
icon: AppIcons.share, onPressed: () => handlePressed(context, () => _handleSharePressed())),
ContextDivider(),
ContextMenuBtn("Delete",
icon: AppIcons.trashcan, onPressed: () => handlePressed(context, () => _handleDeletePressed())),
hoverBgColor: theme.greyStrong,
icon: AppIcons.trashcan,
onPressed: () => handlePressed(context, () => _handleDeletePressed())),
],
);
}
Expand Down
74 changes: 57 additions & 17 deletions lib/styled_widgets/inline_text_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_folio/_utils/string_utils.dart';
import 'package:flutter_folio/_widgets/context_menu_overlay.dart';
import 'package:flutter_folio/core_packages.dart';
import 'package:universal_platform/universal_platform.dart';

//TODO: This is a good package / code example / blogpost
class InlineTextEditor extends StatefulWidget {
Expand Down Expand Up @@ -60,13 +61,17 @@ class _InlineTextEditorState extends State<InlineTextEditor> {

@override
void dispose() {
_textController.dispose();
// Only dispose our internal controller
if (_textController != widget.controller) {
_textController.dispose();
}
_textFocus.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
AppTheme theme = context.watch();
// Measure Size of text using a maxWidth and maxLines so we can reserve a space of that size
String textToMeasure = _textController.text;
Size textSize = StringUtils.measure(textToMeasure, widget.style, maxLines: widget.maxLines, maxWidth: widget.width);
Expand Down Expand Up @@ -110,22 +115,28 @@ class _InlineTextEditorState extends State<InlineTextEditor> {
isEnabled: widget.enableContextMenu,
contextMenu: TextContextMenu(data: _textController.text, controller: _textController),
child: Container(
color: Colors.red.withOpacity(.1),
child: TextFormField(
scrollPhysics: NeverScrollableScrollPhysics(),
onChanged: widget.onChanged,
style: widget.style,
textAlign: widget.align,
textAlignVertical: widget.alignVertical,
focusNode: _textFocus,
controller: _textController,
decoration: InputDecoration(
contentPadding: EdgeInsets.only(top: 10, bottom: 0),
border: InputBorder.none,
isDense: true,
),
minLines: widget.maxLines,
maxLines: widget.maxLines),
color: theme.accent1.withOpacity(.1),
child: RawKeyboardListener(
focusNode: rawFocus,
onKey: (value) {
lastPosition = _textController.selection.start;
},
child: TextFormField(
scrollPhysics: NeverScrollableScrollPhysics(),
onChanged: UniversalPlatform.isLinux ? _fixTextOnLinux : widget.onChanged,
style: widget.style,
textAlign: widget.align,
textAlignVertical: widget.alignVertical,
focusNode: _textFocus,
controller: _textController,
decoration: InputDecoration(
contentPadding: EdgeInsets.only(top: 10, bottom: 0),
border: InputBorder.none,
isDense: true,
),
minLines: widget.maxLines,
maxLines: widget.maxLines),
),
),
),
]
Expand Down Expand Up @@ -153,6 +164,35 @@ class _InlineTextEditorState extends State<InlineTextEditor> {
//_textController.selection = TextSelection(baseOffset: 0, extentOffset: _textController.text.length);
_textFocus.requestFocus();
}

//region Fix for bug: https://github.com/flutter/flutter/issues/76474
// TODO: Remove
String lastValue = "";
int lastPosition;
final FocusNode rawFocus = FocusNode();
@override
void _fixTextOnLinux(String value) {
if (value.length > 1 && lastValue.length < value.length) {
final enteredChar = value[0];
final oldValue = value.substring(1);

final prefix = oldValue.substring(0, lastPosition);
final suffix = oldValue.substring(lastPosition);
final newValue = prefix + enteredChar + suffix;
_textController.value = TextEditingValue(
text: newValue,
selection: TextSelection.collapsed(offset: lastPosition + 1),
);
lastValue = newValue;
lastPosition = lastPosition + 1;
} else {
lastValue = value;
lastPosition = value.length;
}
widget.onChanged(value);
}

//endregion
}

class InlineTextEditorFocusNotification extends Notification {
Expand Down
75 changes: 41 additions & 34 deletions lib/styled_widgets/labeled_text_input.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_folio/_utils/string_utils.dart';
import 'package:flutter_folio/_widgets/context_menu_overlay.dart';
import 'package:flutter_folio/core_packages.dart';
import 'package:flutter_folio/models/app_model.dart';
import 'package:universal_platform/universal_platform.dart';

class LabeledTextInput extends StatefulWidget {
const LabeledTextInput({
Key key,
this.text,
this.label,
this.onChanged,
this.onSubmit,
this.style,
this.labelStyle,
this.numLines = 1,
this.hintText,
this.controller,
this.autofillHints,
this.obscureText,
}) : super(key: key);
const LabeledTextInput(
{Key key,
this.text,
this.label,
this.onChanged,
this.onSubmit,
this.style,
this.labelStyle,
this.numLines = 1,
this.hintText,
this.controller,
this.autofillHints,
this.obscureText,
this.autoFocus = false})
: super(key: key);

final String label;
final String text;
Expand All @@ -32,31 +34,13 @@ class LabeledTextInput extends StatefulWidget {
final TextEditingController controller;
final List<String> autofillHints;
final bool obscureText;
final bool autoFocus;

@override
_LabeledTextInputState createState() => _LabeledTextInputState();
}

class _LabeledTextInputState extends State<LabeledTextInput> {
String lastValue = "";

int lastPosition;

final FocusNode rawFocus = FocusNode();
TextEditingController _controller;

@override
void initState() {
super.initState();
_controller = widget.controller ?? TextEditingController(text: widget.text);
}

@override
void dispose() {
_controller?.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
AppTheme theme = context.watch();
Expand Down Expand Up @@ -88,7 +72,7 @@ class _LabeledTextInputState extends State<LabeledTextInput> {
onFieldSubmitted: widget.onSubmit,
//initialValue: widget.text,
style: widget.style ?? TextStyles.body2,
autofocus: true,
autofocus: widget.autoFocus,
minLines: widget.numLines,
maxLines: widget.numLines,
obscureText: widget.obscureText ?? false,
Expand Down Expand Up @@ -124,6 +108,27 @@ class _LabeledTextInputState extends State<LabeledTextInput> {
);
}

//region Fix for bug: https://github.com/flutter/flutter/issues/76474
// TODO: Remove
String lastValue = "";
int lastPosition;
final FocusNode rawFocus = FocusNode();
TextEditingController _controller;
@override
void initState() {
super.initState();
_controller = widget.controller ?? TextEditingController(text: widget.text);
}

@override
void dispose() {
// Only dispose our internal controller
if (_controller != widget.controller) {
_controller?.dispose();
}
super.dispose();
}

void _fixTextOnLinux(String value) {
if (value.length > 1 && lastValue.length < value.length) {
final enteredChar = value[0];
Expand All @@ -144,4 +149,6 @@ class _LabeledTextInputState extends State<LabeledTextInput> {
}
widget.onChanged(value);
}

//endregion
}
3 changes: 3 additions & 0 deletions lib/views/auth_page/auth_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:email_validator/email_validator.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_folio/_utils/input_utils.dart';
import 'package:flutter_folio/_widgets/context_menu_overlay.dart';
import 'package:flutter_folio/_widgets/flexibles/seperated_flexibles.dart';
import 'package:flutter_folio/_widgets/mixins/loading_state_mixin.dart';
Expand Down Expand Up @@ -85,6 +86,7 @@ class _AuthPageState extends State<AuthPage> with LoadingStateMixin {
LabeledTextInput(
onSubmit: (_) => _handleSubmitPressed(),
controller: _emailController,
autoFocus: true,
style: TextStyles.body1,
hintText: "Email",
autofillHints: [AutofillHints.email, AutofillHints.username],
Expand Down Expand Up @@ -150,5 +152,6 @@ class _AuthPageState extends State<AuthPage> with LoadingStateMixin {
formMode = isCreatingAccount ? _AuthFormMode.SignIn : _AuthFormMode.CreateAccount;
_emailController.text = "";
_passController.text = "";
InputUtils.unFocus();
}
}
5 changes: 4 additions & 1 deletion lib/views/books_home/book_cover/book_cover_large.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:animate_do/animate_do.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_folio/commands/books/set_current_book_command.dart';
Expand Down Expand Up @@ -70,7 +71,9 @@ class _LargeBookCoverState extends State<LargeBookCover> {
onFocusIn: _handleEditingStarted,
onFocusOut: _handleDescEditingEnded,
width: 370,
style: TextStyles.body1.copyWith(height: 1.8, color: theme.greyWeak),
// SB: Set web to 1 instead of 1.8, it was causing rendering issues where the text would get cut-off.
// TODO: Log bug on this ^
style: TextStyles.body1.copyWith(height: kIsWeb ? 1 : 1.8, color: theme.greyWeak),
maxLines: 3),
VSpace(Insets.xl * 1.2 * paddingScale),

Expand Down
4 changes: 2 additions & 2 deletions lib/views/books_home/books_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ class _EmptyHomeView extends StatelessWidget {
padding: EdgeInsets.all(Insets.offset),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Spacer(),
Text("Welcome to flutterfolio", style: TextStyles.h1.copyWith(color: Colors.white)),
Text("Welcome to Flutter Folio!", style: TextStyles.h1.copyWith(color: Colors.white)),
VSpace.sm,
SizedBox(
width: 380,
child: Text(
"Suspendisse sed libero eget purus efficitur sodales non vel elit. Nulla egestas elit sed enim aliquam rutrum. Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"Create beautiful scrap books and share them with your friends and family. To get started, create a new Folio and upload some pictures!",
style: TextStyles.body1.copyWith(color: Colors.white)),
),
VSpace.xl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ScrapPilePickerTitleBar extends StatelessWidget {
onPressed: onClosePressed)
],
),
Center(child: Text(title, style: TextStyles.title1))
Center(child: SelectableText(title, style: TextStyles.title1))
],
),
);
Expand Down
Loading