Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New changes and improvemenets #1437

Merged
merged 7 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
// I removed the todo because it's not required for this example
EchoEllet marked this conversation as resolved.
Show resolved Hide resolved
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
Expand All @@ -53,7 +53,7 @@ android {

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// I removed the todo because it's not required for this example
EchoEllet marked this conversation as resolved.
Show resolved Hide resolved
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
Expand Down
8 changes: 7 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />

<uses-feature android:name="android.hardware.camera" android:required="false" />
<application
android:name="${applicationName}"
android:label="app"
Expand Down
24 changes: 12 additions & 12 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,23 @@ class _HomePageState extends State<HomePage> {
onTapUp: (details, p1) {
return _onTripleClickSelection();
},
customStyles: DefaultStyles(
customStyles: const DefaultStyles(
h1: DefaultTextBlockStyle(
const TextStyle(
TextStyle(
fontSize: 32,
color: Colors.black,
height: 1.15,
fontWeight: FontWeight.w300,
),
const VerticalSpacing(16, 0),
const VerticalSpacing(0, 0),
VerticalSpacing(16, 0),
VerticalSpacing(0, 0),
null),
sizeSmall: const TextStyle(fontSize: 9),
subscript: const TextStyle(
sizeSmall: TextStyle(fontSize: 9),
subscript: TextStyle(
fontFamily: 'SF-UI-Display',
fontFeatures: [FontFeature.subscripts()],
),
superscript: const TextStyle(
superscript: TextStyle(
fontFamily: 'SF-UI-Display',
fontFeatures: [FontFeature.superscripts()],
),
Expand All @@ -230,18 +230,18 @@ class _HomePageState extends State<HomePage> {
onTapUp: (details, p1) {
return _onTripleClickSelection();
},
customStyles: DefaultStyles(
customStyles: const DefaultStyles(
h1: DefaultTextBlockStyle(
const TextStyle(
TextStyle(
fontSize: 32,
color: Colors.black,
height: 1.15,
fontWeight: FontWeight.w300,
),
const VerticalSpacing(16, 0),
const VerticalSpacing(0, 0),
VerticalSpacing(16, 0),
VerticalSpacing(0, 0),
null),
sizeSmall: const TextStyle(fontSize: 9),
sizeSmall: TextStyle(fontSize: 9),
),
embedBuilders: [
...defaultEmbedBuildersWeb,
Expand Down
71 changes: 12 additions & 59 deletions flutter_quill_extensions/lib/embeds/builders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ class ImageEmbedBuilder extends EmbedBuilder {
OptionalSize? imageSize;
final style = node.style.attributes['style'];

// TODO: Please use the one from [Attribute.margin]
const marginKey = 'margin';
// TODO: Please use the one from [Attribute.alignment]
const alignmentKey = 'alignment';
if (style != null) {
final attrs = base.isMobile()
? base.parseKeyValuePairs(style.value.toString(), {
Expand All @@ -70,8 +66,8 @@ class ImageEmbedBuilder extends EmbedBuilder {
: base.parseKeyValuePairs(style.value.toString(), {
Attribute.width.key,
Attribute.height.key,
marginKey,
alignmentKey,
Attribute.margin,
Attribute.alignment,
});
if (attrs.isNotEmpty) {
final width = double.tryParse(
Expand All @@ -88,10 +84,10 @@ class ImageEmbedBuilder extends EmbedBuilder {
);
final alignment = base.getAlignment(base.isMobile()
? attrs[Attribute.mobileAlignment]
: attrs[alignmentKey]);
: attrs[Attribute.alignment]);
final margin = (base.isMobile()
? double.tryParse(Attribute.mobileMargin)
: double.tryParse(marginKey)) ??
: double.tryParse(Attribute.margin)) ??
0.0;

assert(
Expand Down Expand Up @@ -198,57 +194,14 @@ class ImageEmbedBuilder extends EmbedBuilder {
controller,
controller.selection.start,
);
// For desktop
String _replaceStyleStringWithSize(
String s,
double width,
double height,
) {
final result = <String, String>{};
final pairs = s.split(';');
for (final pair in pairs) {
final _index = pair.indexOf(':');
if (_index < 0) {
continue;
}
final _key =
pair.substring(0, _index).trim();
result[_key] =
pair.substring(_index + 1).trim();
}

result[Attribute.width.key] =
width.toString();
result[Attribute.height.key] =
height.toString();
final sb = StringBuffer();
for (final pair in result.entries) {
sb
..write(pair.key)
..write(': ')
..write(pair.value)
..write('; ');
}
return sb.toString();
}

// TODO: When update flutter_quill
// we should update flutter_quill_extensions
// to use the latest version and use
// base.replaceStyleStringWithSize()
// instead of replaceStyleString

final attr = base.isMobile()
? base.replaceStyleString(
getImageStyleString(controller),
w,
h,
)
: _replaceStyleStringWithSize(
getImageStyleString(controller),
w,
h,
);

final attr =
base.replaceStyleStringWithSize(
getImageStyleString(controller),
width: w,
height: h,
isMobile: base.isMobile(),
);
controller
..skipRequestKeyboard = true
..formatText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ class CameraButton extends StatelessWidget {
break;
case MediaPickSetting.Gallery:
throw ArgumentError(
'Invalid MediaSetting for the camera button',
'Invalid MediaSetting for the camera button.\n'
'gallery is not related to camera button',
);
case MediaPickSetting.Link:
throw ArgumentError(
'Invalid MediaSetting for the camera button',
'Invalid MediaSetting for the camera button.\n'
'link is not related to camera button',
);
}
}
Expand Down
54 changes: 35 additions & 19 deletions flutter_quill_extensions/lib/embeds/toolbar/image_video_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,52 @@ class LinkDialogState extends State<LinkDialog> {
super.initState();
_link = widget.link ?? '';
_controller = TextEditingController(text: _link);
// TODO: Consider replace the default Regex with this one
// Since that is not the reason I sent the changes then I will not edit it

// TODO: Consider use one of those as default or provide a
// way to custmize the check, that are not based on RegExp,
// I already implemented one so tell me if you are interested
final defaultLinkNonSecureRegExp = RegExp(
r'https?://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)',
caseSensitive: false,
); // Not secure
// final defaultLinkRegExp = RegExp(
// r'https://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)',
// caseSensitive: false,
// ); // Secure
_linkRegExp = widget.linkRegExp ?? defaultLinkNonSecureRegExp;
}

// final defaultLinkNonSecureRegExp = RegExp(r'https?://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)'); // Not secure
// final defaultLinkRegExp = RegExp(r'https://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)'); // Secure
// _linkRegExp = widget.linkRegExp ?? defaultLinkRegExp;
_linkRegExp = widget.linkRegExp ?? AutoFormatMultipleLinksRule.linkRegExp;
@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: widget.dialogTheme?.dialogBackgroundColor,
content: TextField(
keyboardType: TextInputType.multiline,
keyboardType: TextInputType.url,
textInputAction: TextInputAction.done,
maxLines: null,
style: widget.dialogTheme?.inputTextStyle,
decoration: InputDecoration(
labelText: 'Paste a link'.i18n,
hintText: 'Please enter a valid image url'.i18n,
labelStyle: widget.dialogTheme?.labelTextStyle,
floatingLabelStyle: widget.dialogTheme?.labelTextStyle,
),
autofocus: true,
onChanged: _linkChanged,
controller: _controller,
onEditingComplete: () {
if (!_canPress()) {
return;
}
_applyLink();
},
),
actions: [
TextButton(
onPressed: _link.isNotEmpty && _linkRegExp.hasMatch(_link)
? _applyLink
: null,
onPressed: _canPress() ? _applyLink : null,
child: Text(
'Ok'.i18n,
style: widget.dialogTheme?.labelTextStyle,
Expand All @@ -88,6 +99,10 @@ class LinkDialogState extends State<LinkDialog> {
void _applyLink() {
Navigator.pop(context, _link.trim());
}

bool _canPress() {
return _link.isNotEmpty && _linkRegExp.hasMatch(_link);
}
}

class ImageVideoUtils {
Expand Down Expand Up @@ -179,12 +194,13 @@ class ImageVideoUtils {

/// For video picking logic
static Future<void> handleVideoButtonTap(
BuildContext context,
QuillController controller,
ImageSource videoSource,
OnVideoPickCallback onVideoPickCallback,
{FilePickImpl? filePickImpl,
WebVideoPickImpl? webVideoPickImpl}) async {
BuildContext context,
QuillController controller,
ImageSource videoSource,
OnVideoPickCallback onVideoPickCallback, {
FilePickImpl? filePickImpl,
WebVideoPickImpl? webVideoPickImpl,
}) async {
final index = controller.selection.baseOffset;
final length = controller.selection.extentOffset - index;

Expand Down
Loading