-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.dart
117 lines (101 loc) · 3.53 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:magic_text/magic_text.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Magic Text Windows Linux MacOs and Web.',
debugShowCheckedModeBanner: false,
home: MyHomePage(title: 'MagicTextDemo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static const double HORIZONTAL_CONTAINER_MARGIN = 20;
double? originalWidth;
double? containerWidth;
bool isGrowing = true;
int step = 1;
@override
void initState() {
super.initState();
}
void _initAnimation() {
WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((timeStamp) {
Timer.periodic(const Duration(milliseconds: 3500), (timer) {
if (isGrowing) {
_updateContainerWidth(++step);
if (step >= 4) isGrowing = false;
} else {
_updateContainerWidth(--step);
if (step <= 1) isGrowing = true;
}
});
});
}
void _updateContainerWidth(int step) {
setState(() {
containerWidth = (step / 4) * originalWidth!;
});
print(
'step $step, originalWidth: $originalWidth , containerWidth: $containerWidth');
}
@override
Widget build(BuildContext context) {
containerWidth ??=
MediaQuery.of(context).size.width - HORIZONTAL_CONTAINER_MARGIN * 2;
return Scaffold(
backgroundColor: const Color.fromARGB(255, 40, 40, 40),
body: SafeArea(
child: Column(
children: [
Expanded(
child: AnimatedContainer(
duration: const Duration(milliseconds: 600),
curve: Curves.decelerate,
padding: const EdgeInsets.all(15),
margin: const EdgeInsets.fromLTRB(HORIZONTAL_CONTAINER_MARGIN,
40, HORIZONTAL_CONTAINER_MARGIN, 30),
width: containerWidth,
decoration: const BoxDecoration(
color: Color.fromARGB(255, 242, 25, 105),
borderRadius: BorderRadius.all(Radius.circular(20))),
child: LayoutBuilder(
builder: (BuildContext, BoxConstraints) {
if (originalWidth == null) {
originalWidth =
BoxConstraints.maxWidth + HORIZONTAL_CONTAINER_MARGIN;
_initAnimation();
}
MagicText magicText = MagicText(
"The Flutter framework has been optimized to make rerunning build methods fast, so that you can just rebuild anything that needs updating rather than having to individually change instances of widgets.",
breakWordCharacter: '-',
smartSizeMode: true,
asyncMode: true,
minFontSize: 19,
maxFontSize: 26,
textStyle: const TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold),
);
return magicText;
},
),
))
],
),
));
}
}