Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
78
Task/Animation/Dart/animation-1.dart
Normal file
78
Task/Animation/Dart/animation-1.dart
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'dart:async' show Timer;
|
||||
|
||||
void main() {
|
||||
|
||||
var timer = const Duration( milliseconds: 75 ); // How often to update i.e. how fast the animation is
|
||||
|
||||
runApp(MaterialApp (
|
||||
home: Scaffold (
|
||||
body: Center (
|
||||
child: AnimatedText( timer )
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
class AnimatedText extends StatefulWidget {
|
||||
|
||||
final Duration period; // Time period for update
|
||||
|
||||
AnimatedText( this.period );
|
||||
@override
|
||||
_AnimatedText createState() => _AnimatedText( period );
|
||||
}
|
||||
|
||||
|
||||
class _AnimatedText extends State<AnimatedText> {
|
||||
|
||||
bool forward = true; // Text should go forward?
|
||||
|
||||
Timer timer; // Timer Objects allow us to do things based on a period of time
|
||||
// We want to get an array of characters, but Dart does not have a char type
|
||||
// Below is the equivalent code
|
||||
var _text = 'Hello World! '.runes // .runes gives us the unicode number of each character
|
||||
.map( (code) => String.fromCharCode(code) ) // Map all these codes to Strings containing the single character
|
||||
.toList(); // Conver to a List
|
||||
|
||||
_AnimatedText( Duration period ){
|
||||
timer = Timer.periodic( period , (_){
|
||||
setState((){ // Set state forces the gui elements to be redrawn
|
||||
shiftText();
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
String get text => _text.join(''); // Getter, joins the list of chars into a string
|
||||
|
||||
void shiftText() {
|
||||
if (forward) { // If we should go forward
|
||||
var last = _text.removeLast(); // Remove the last char
|
||||
|
||||
_text.insert( 0, last); // Insert it at the front
|
||||
|
||||
} else { // If we should go backward
|
||||
var first = _text.removeAt(0); // Remove the first char
|
||||
|
||||
_text.insert( _text.length, first ); // Insert it at the end
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector( // GestureDetector lets us capture events
|
||||
onTap: () => forward = !forward, // on Tap (Click in browser) invert the forward bool
|
||||
child: Text(
|
||||
text, // Call the text getter to get the shifted string
|
||||
style: TextStyle( // Styling
|
||||
fontSize: 50,
|
||||
color: Colors.grey[600]
|
||||
)
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
26
Task/Animation/Dart/animation-2.dart
Normal file
26
Task/Animation/Dart/animation-2.dart
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import 'dart:html';
|
||||
import 'dart:async';
|
||||
|
||||
const frameTime = const Duration(milliseconds: 100);
|
||||
|
||||
void main() {
|
||||
String text = "Hello World! ";
|
||||
bool rotateRight = true;
|
||||
|
||||
Element writeHere =
|
||||
querySelector('#output'); // assumes you have a pre with that ID
|
||||
writeHere.onClick.listen((event) => rotateRight = !rotateRight);
|
||||
|
||||
new Timer.periodic(frameTime, (_) {
|
||||
text = changeText(text, rotateRight);
|
||||
writeHere.text = text;
|
||||
});
|
||||
}
|
||||
|
||||
String changeText(extt, rotateRight) {
|
||||
if (rotateRight) {
|
||||
return extt.substring(extt.length - 1) + extt.substring(0, extt.length - 1);
|
||||
} else {
|
||||
return extt.substring(1) + extt.substring(0, 1);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue