Related
Is it possible to check if a SingleChildScrollView fits in a screen so it doesn't need scrolling?
I want to achieve different behaviours based on this information.
Thanks to everyone in advance.
I had the same issue, and found a way around this. Here's how I made it:
Theory:
You need to provide a scroll controller to your SingleChildScrollView.
The reason is that the "[...] scroll controller creates a ScrollPosition to manage the state specific to an individual Scrollable widget", and we'll use exactly that to determine if the contents of our scrollable widget fits in the screen.
The property we're interested in is maxScrollExtent. It belongs to the ScrollPosition, and indicates the "maximum in-range value for pixels" that we can scroll to.
How:
The way I used it was to check if this value is greater than zero:
If so, then the contents do not fit in the given height.
Otherwise, if it's equal to zero, then the contents of the scrollable fits the screen.
Caveats in using this approach:
The child's size is a reflex of the build, so you can't know in advance if it will be scrollable or not. But what we can do is add a post frame callback to be executed after the build. By that point, when this callback is run, the build has already occurred, so we can check if the child fits in the screen or not.
Problem is, we need a StatefulWidget to do so. In that, we can schedule a post frame callback either in the initState() override - which will run only once during the widget's lifecycle, or in didChangeDependencies() - which runs whenever the widget needs rebuilding due a dependency change. See what fits best to your purpose.
TL;DR:
Here's a sample that shows how to take advantage of maxScrollExtent. Try running it in a flutter dartpad and change the width of the preview:
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
// Here's the important widget
class MyWidget extends StatefulWidget {
#override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
final ScrollController _controller = ScrollController();
#override
void didChangeDependencies() {
super.didChangeDependencies();
WidgetsBinding.instance.addPostFrameCallback((_) {
// Checks to see the controller's [ScrollMetrics] maxScrollExtent.
// If zero, then the entire scrollable fits in the screen's viewport.
// So, triggers fadeoutController.reverse() to make scrollbar go away.
var maxScrollExtent = _controller.position.maxScrollExtent;
if (maxScrollExtent == 0) {
print('Fits entirely');
} else {
print('Needs scrolling');
}
});
}
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
controller: _controller,
child: Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
child: Text(_text),
),
],
),
);
}
}
// very, very long lorem ipsum so that we can get to scroll if it doesn't fit.
const String _text = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper, massa ac dignissim elementum, sapien nibh faucibus nibh, vel fermentum justo augue non est. Vestibulum at diam a orci hendrerit pellentesque vitae et tortor. Donec vel ultricies ipsum. Morbi eleifend dolor eget risus dignissim tempor. Curabitur suscipit eros turpis, id iaculis odio fringilla nec. Phasellus ullamcorper lacus nec dapibus euismod. Aenean convallis euismod pellentesque. Integer congue libero in turpis dapibus, vitae condimentum ex elementum. Nullam condimentum, turpis eget tincidunt ultrices, orci mi maximus ex, sit amet tempor nulla mi quis libero. Sed congue elementum magna, ut luctus felis congue ut. Aliquam fringilla tortor at elit tempus venenatis. Quisque porta commodo nisi, sit amet rhoncus arcu dapibus non. Nam sit amet ullamcorper dui. Quisque dui dolor, tincidunt in urna sit amet, ultricies egestas libero.
Sed at lorem magna. Sed dignissim ullamcorper convallis. Nunc ornare, urna eget sodales feugiat, sem odio eleifend felis, a blandit lorem mi sed orci. Nulla facilisi. Pellentesque sed mi scelerisque, sollicitudin nunc non, ullamcorper neque. Quisque purus magna, lacinia vel ex a, tempor viverra ante. Phasellus volutpat nulla nec aliquet sollicitudin. Morbi ultricies dapibus scelerisque. Pellentesque ut elit justo. Phasellus eget tempus massa. Curabitur id enim mollis, rutrum lorem in, aliquet diam. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin semper ultricies orci. Nunc tempor fermentum dolor, placerat aliquam arcu ullamcorper sed. Cras eleifend erat gravida, mattis dolor eu, mollis lorem. Donec eu aliquet mauris, a egestas tortor.
Vivamus eu lorem erat. Phasellus condimentum quam quam, semper mattis odio dapibus vitae. Nulla eleifend lectus malesuada sem feugiat elementum. Phasellus semper luctus sodales. Aenean facilisis eu purus eget ultricies. Mauris non hendrerit lectus. Donec mollis ante non viverra euismod. Nulla aliquam, quam a rutrum dictum, tortor magna sagittis diam, non pulvinar erat nibh id nibh. Aliquam rutrum, mauris sit amet eleifend convallis, orci arcu egestas purus, vel dignissim tellus quam sit amet dolor. In hac habitasse platea dictumst. Etiam justo orci, sagittis a arcu vitae, viverra fringilla nunc. Maecenas ac semper ligula. Suspendisse ultrices tellus placerat nisl euismod pharetra.
Quisque et tellus ut magna efficitur volutpat ut nec metus. Vestibulum sed turpis id justo porta sagittis vitae et ligula. Aliquam ultricies tortor nulla, laoreet efficitur dui dictum eget. Aenean at ante a odio ornare pharetra in eget metus. Fusce vulputate luctus tortor in convallis. Praesent a velit libero. Proin molestie condimentum commodo. Nullam congue massa a odio congue, a bibendum tortor vestibulum. Etiam pellentesque dapibus libero. Donec iaculis vitae ante luctus varius.
Donec eleifend, elit eget accumsan rhoncus, diam nunc luctus dui, eu accumsan arcu sapien sed urna. Vivamus non viverra tellus, eget tincidunt nisl. Suspendisse nec laoreet risus. Vestibulum sit amet est elit. Duis vestibulum maximus magna ut dignissim. Mauris suscipit fermentum sapien sit amet finibus. Morbi quis lectus tincidunt nibh malesuada auctor non at neque. Fusce in tortor dictum, ornare felis ut, fermentum justo. Nulla ullamcorper viverra bibendum. Aliquam erat volutpat. Mauris et neque in purus auctor bibendum. Proin posuere enim id egestas scelerisque. In sollicitudin velit a ex fringilla, nec vulputate arcu volutpat. Mauris euismod sapien justo, sit amet pulvinar nisl volutpat quis. Sed finibus, leo vel molestie porta, quam est placerat mauris, vitae placerat eros turpis porta lorem. Donec at tortor tortor.''';
Can't seem to wrap my head around the proper regex!
MY GOAL
add 2 spaces to each line of a selected block of text
MY CONTEXT
some markdown tools I used need 2 spaces at the end of each line to properly manage lists, etc.
if a file is edited multiple times, I do not want to end up with lines ending with 4+ spaces
a block of text can be a line, a paragraph, the whole file content as shown in the editor
I have some kind of macro in Notepad++ that does the trick but I want to do the same with Autohotkey to be editor-independant
MY EXAMPLE
----
# 2020-03-17
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a,
MY SNIPPET SO FAR
; CTL+SHIFT+F12
^+F12::
Clipboard = ; Empty the clipboard so that ClipWait has something to detect
SendInput, ^c ; Copy selected text
ClipWait
OutputText := ""
Loop, parse, Clipboard, `n, `r
{
OutputText .= RegExReplace(A_LoopField,"m)^(.*) *$","$1 `r`n")
}
SendRaw % OutputText
return
MY PROBLEM
Between the character ignored when looping, what I am trying to match and what I try to replace the group with, I end up with far more lines and spaces than needed.
CURRENT OUTPUT
----
# 2020-03-17
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a,
DESIRED OUTPUT
----
# 2020-03-17
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a,
You're getting too many lines in the output because the send command is messing up due to the carriage returns, which aren't needed in there anyway. I don't really know why that is happening, and I can't be bothered to find out why since the approach isn't good anyway.
And also your indentation is getting messed up because your text editor automatically adds indentation based on the previous line.
But anyway, sending such (long) input is never a good idea.
Make use of the clipboard and just send a ctrl+v to instantly and reliably paste in the text.
Here's an example of that along another way to add the spaces at the end:
inp := "
(
----
# 2020-03-17
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a,
)"
Loop, Parse, inp, `n, `r
OutputText .= (A_LoopField = "" ? "" : RTrim(A_LoopField) " ") "`n"
Clipboard := OutputText
SendInput, ^v
The ternary A_LoopField = "" ? "" : RTrim(A_LoopField) " " returns true if the line was empty and then the two spaces aren't added at the end.
I think that's the behavior you were doing for.
And RTrim is used to trim any trailing spaces (or tabs) off the end, so we're sure to end up with just the two we want.
And, of course, at the end of any line we add one line feed `n.
Also, your Regex approach was just fine as well at first it just seemed off to me, but well, here's another way. And I guess this would be more efficient, though you'd have to work with seriously large inputs and/or slow hardware for that to make any meaningful difference haha.
I am trying to create a script which takes file from the user, encode it in base64 and then forward it to an email as attachment with encoded file.
This is the code till now :
Client side :
<form action="send.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file">
<input type="submit" value="Submit" name='submit'>
</form>
PHP Script (send.php)
<?php
$uploaded_file = basename($_FILES['uploaded_file']['name']);
$file_size = filesize($uploaded_file);
$handle = fopen($uploaded_file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content1 = base64_encode($content);
$my_file = "'$encoded_file' . '_encoded' . '.html'";
$handle1 = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
fwrite($handle1, $content1);
$from="tes#gmail.com";
$to="myemail#gmail.com"
$subject="New file";
$message="you got a new file";
mail($from,$to,$subject,$message);
unlink($my_file);
?>
I don't know how to attach $myfile in the email.
You can just use PHPMailer
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = preg_replace('/[\]/', '', $body);
$mail->SetFrom('tes#gmail.com', 'First Last');
$mail->AddReplyTo("tes#gmail.com", "First Last");
$mail->AddAddress("myemail#gmail.com", "John Doe");
$mail->Subject = "New File";
$mail->AltBody = "you got a new file";
$mail->MsgHTML($body);
$my_file = file_put_contents("tmp.html", base64_encode($content));
$mail->AddAttachment($my_file); // attachment
if (! $mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
If you're not using any external mail libraries such as PEAR::SMTP or Swift then creating the attachments is not a simple thing.
You will have to check the mail standards they instruct on how to separate the headers from the message content and the message content from the attachments.
The separator is \r\n and each section must be preceded by a separator.
Check this link out: http://webcheatsheet.com/php/send_email_text_html_attachment.php
And my code example:
$uid = md5(uniqid(time()));
$header = implode("\r\n",
array(
'MIME-Version: 1.0',
'From: Address <address#example.com>',
'Reply-To: Address <address#example.com>',
'Cc: Address <address#example.com>',
'Content-Type: multipart/mixed;',
' boundary="'.$uid.'"',
'',
'--'.$uid,
'Content-Type: text/plain;',
' charset="us-ascii"',
'Content-Transfer-Encoding: 7bit',
'',
mb_convert_encoding(
implode("\r\n",
array_map('wordwrap',
array(
'Hello,',
'',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla laoreet varius augue non pretium. Nullam dignissim iaculis velit, ut cursus neque mollis et. Fusce faucibus dictum nunc, sit amet cursus tellus aliquam ut. Praesent id libero orci, ut vehicula orci. Proin nulla sem, dapibus in lacinia vel, pharetra eget eros. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras rhoncus, enim sed mollis suscipit, sapien mauris suscipit mauris, nec placerat nisi sapien ac lectus. Sed vehicula faucibus iaculis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer placerat commodo nibh. Morbi sit amet augue vitae urna mattis pulvinar ac eget tellus. Donec mattis cursus posuere. Donec dolor velit, aliquam eu pretium vel, accumsan eu est. Proin at ante nisi, ut malesuada diam.',
'',
'Nulla ac urna lacus, in luctus ipsum. Nunc luctus risus non dui tincidunt in ultricies tellus rhoncus. Aliquam pellentesque vehicula adipiscing. Phasellus porttitor sodales quam et cursus. Pellentesque iaculis consectetur lorem, et consectetur sem tristique sed. Duis vehicula eleifend nisl, a semper augue lobortis cursus. Fusce ut ligula diam. Quisque fringilla sodales massa vitae rhoncus. Pellentesque a libero sed enim lacinia commodo quis et dolor. Praesent facilisis, orci nec lacinia ultrices, enim nunc imperdiet augue, at aliquet dolor augue nec nulla.',
'',
'Ut venenatis commodo pulvinar. Vestibulum quam odio, malesuada posuere porttitor facilisis, molestie vel risus. Mauris auctor fringilla ornare. Morbi eu libero orci, nec semper lorem. Quisque blandit, ante nec pharetra bibendum, felis felis tincidunt felis, sed mattis sapien lorem et risus. In sed interdum quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas vitae metus id purus ultrices fermentum. In dui eros, feugiat sit amet feugiat vel, accumsan vitae ligula. Nam at consectetur elit. Maecenas eget metus id nibh luctus mattis. Quisque mollis, sapien semper vulputate venenatis, purus arcu ornare orci, sit amet pellentesque enim ipsum non urna. Quisque at augue nec quam vehicula suscipit eu a dui. Morbi at molestie nunc. Mauris ultricies rutrum euismod. Sed non sem nisi. '
)
)
),
'iso-8859-1'
),
'',
'--'.$uid,
'Content-Type: application/pdf;',
' name="file.pdf"',
'Content-Transfer-Encoding: base64',
'Content-Disposition: attachment;',
' filename="file.pdf"',
'',
chunk_split(base64_encode(file_get_contents('file.pdf'))),
'--'.$uid.'--'
)
);
mail($contacts, 'Subject', '', $header);
is it possoble to set the editable area of TinyMce to have different areas like this:
I tried setting creating differeent areas inside the the area I made editable with TinyMce, but the user was able to delete those areas. (e.g with the rightclick delete Table).
This is the html I used for creating the TinyMce area:
<div id="elm1" name="elm1" style="width: 80%" class="tinymce">
<table>
<tr>
<td colspan="2"><h1>Hello world</h1></td>
</tr>
<td> Nam nisi elit, cursus in rhoncus sit amet, pulvinar laoreet leo. Nam sed lectus quam, ut sagittis tellus. Quisque dignissim mauris a augue rutrum tempor. Donec vitae purus nec massa vestibulum ornare sit amet id tellus. Nunc quam mauris, fermentum nec lacinia eget, sollicitudin nec ante. Aliquam molestie volutpat dapibus. Nunc interdum viverra sodales. Morbi laoreet pulvinar gravida. Quisque ut turpis sagittis nunc accumsan vehicula. Duis elementum congue ultrices. Cras faucibus feugiat arcu quis lacinia. In hac habitasse platea dictumst. Pellentesque fermentum magna sit amet tellus varius ullamcorper. Vestibulum at urna augue, eget varius neque. Fusce facilisis venenatis dapibus. Integer non sem at arcu euismod tempor nec sed nisl. Morbi ultricies, mauris ut ultricies adipiscing, felis odio condimentum massa, et luctus est nunc nec eros. </td>
<td> Nam nisi elit, cursus in rhoncus sit amet, pulvinar laoreet leo. Nam sed lectus quam, ut sagittis tellus. Quisque dignissim mauris a augue rutrum tempor. Donec vitae purus nec massa vestibulum ornare sit amet id tellus. Nunc quam mauris, fermentum nec lacinia eget, sollicitudin nec ante. Aliquam molestie volutpat dapibus. Nunc interdum viverra sodales. Morbi laoreet pulvinar gravida. Quisque ut turpis sagittis nunc accumsan vehicula. Duis elementum congue ultrices. Cras faucibus feugiat arcu quis lacinia. In hac habitasse platea dictumst. Pellentesque fermentum magna sit amet tellus varius ullamcorper. Vestibulum at urna augue, eget varius neque. Fusce facilisis venenatis dapibus. Integer non sem at arcu euismod tempor nec sed nisl. Morbi ultricies, mauris ut ultricies adipiscing, felis odio condimentum massa, et luctus est nunc nec eros. </td>
</table>
</div>
This is possible, but you will have to take care of the non-deletion yourself using an own plugin. For this you will need to intercept all possible deletion events like (backspace, delete, copy/paste, selecting + typing, cmd+x) and handle them yourself which is quite some work.
I have read so much and still no real answer. How can I get iFrames to work on the iPhone and iPad? Especially now you can't 2 finger scroll. I just want to have an iFrame scroll or something that functions like one. I feel like this should be so simple!
Here is a sample page:
http://olbrichdesigns.com/ffff/characters/test.html
Thanks!
jenny
Mobile safari supports them but generally they're not great.
Using a DIV with overflow-y: scroll would probably be better for you
<div style="overflow-y: scroll; height: 100px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam at laoreet augue. Pellentesque felis arcu, convallis eu luctus vitae, imperdiet ut est. Nulla rhoncus varius odio, non facilisis felis imperdiet pellentesque. Aliquam in luctus orci. Ut convallis felis sodales diam ultricies in elementum ligula ultricies. Vivamus consequat convallis mauris, sed ullamcorper ante fermentum a. Quisque at velit eu velit venenatis faucibus id vel velit. Integer eget nisi elit. Ut blandit eros lorem, sed feugiat nunc. Sed lacus nisi, placerat sit amet blandit feugiat, accumsan ut urna. Proin risus sapien, porttitor sed euismod quis, adipiscing vitae nulla. Vestibulum at ipsum vel tortor fermentum tristique. Fusce laoreet magna vitae tellus accumsan eget adipiscing velit ullamcorper. Proin tempus volutpat fringilla. Etiam eu magna sit amet mi commodo volutpat sit amet eget lacus. Nullam euismod tellus id odio tempus id tincidunt felis mollis.
</div>