Skip to content

Instantly share code, notes, and snippets.

@sawin0
Created February 20, 2024 06:05
Show Gist options
  • Save sawin0/730bebe6ebb5ee3e03ea9f4f9f481686 to your computer and use it in GitHub Desktop.
Save sawin0/730bebe6ebb5ee3e03ea9f4f9f481686 to your computer and use it in GitHub Desktop.
Retro pixel-style loading animations, created with Flutter
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: Center(
child: LoadingText(),
),
),
);
}
}
class LoadingText extends StatefulWidget {
const LoadingText({super.key});
@override
State<LoadingText> createState() => _LoadingTextState();
}
class _LoadingTextState extends State<LoadingText> {
late Timer _timer;
int _counter = 0;
//TODO: update default loading... text by your text...
final List<String> _loadingTexts = [
'\\Loading',
'L\\oading.',
'Lo\\ading..',
'Loa\\ding...',
'Load\\ing...',
'Loadi\\ng...',
'Loadin\\g...',
'Loading\\...',
'Loading.\\..',
'Loading..\\.',
'Loading...\\',
];
@override
void initState() {
super.initState();
_startTimer();
}
@override
void dispose() {
_timer.cancel();
super.dispose();
}
void _startTimer() {
_counter = 0;
//TODO: update text updating timer
_timer = Timer.periodic(const Duration(milliseconds: 250), (timer) {
setState(() {
_counter++;
});
});
}
@override
Widget build(BuildContext context) {
final String loadingText = _loadingTexts[_counter % 10];
return Text(
loadingText,
style: const TextStyle(
fontSize: 24.0,
fontFamily: 'Monospace',
color: Colors.green,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment