From 704cfefa788eb59cbda3da2020d3e71de9a067af Mon Sep 17 00:00:00 2001 From: Mohamed Hisham Abdelzaher Date: Mon, 15 Jul 2024 18:29:15 +0300 Subject: [PATCH] change effect --- lib/Pages/home.dart | 37 +++++++++++++++++++++---------------- lib/controller.dart | 26 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 lib/controller.dart diff --git a/lib/Pages/home.dart b/lib/Pages/home.dart index 50fe3c7..d8f7ace 100644 --- a/lib/Pages/home.dart +++ b/lib/Pages/home.dart @@ -1,4 +1,5 @@ import 'package:mh0386/Pages/resume.dart'; +import 'package:mh0386/controller.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -10,6 +11,7 @@ class Home extends StatelessWidget { @override Widget build(BuildContext context) { + final textController = Get.put(TextController()); return MaterialApp( title: 'Mohamed Hisham Abdelzaher', debugShowCheckedModeBanner: false, @@ -198,22 +200,25 @@ class Home extends StatelessWidget { ), ), ), - Animate( - effects: const [ - FadeEffect( - delay: Duration(seconds: 1), - duration: Duration(seconds: 5), - ), - ], - child: Text( - 'I am an Undergraduate Student', - style: TextStyle( - color: Colors.white, - fontSize: (MediaQuery.of(context).size.width * 0.04 < - MediaQuery.of(context).size.height * 0.04) - ? MediaQuery.of(context).size.width * 0.04 - : MediaQuery.of(context).size.height * 0.04, - fontFamily: GoogleFonts.jetBrainsMono().fontFamily, + Obx( + () => Animate( + effects: const [ + FadeEffect( + delay: Duration(seconds: 1), + duration: Duration(seconds: 3), + ), + ], + child: Text( + textController.texts[textController.currentIndex.value], + key: ValueKey(textController.currentIndex.value), + style: TextStyle( + color: Colors.white, + fontSize: (MediaQuery.of(context).size.width * 0.04 < + MediaQuery.of(context).size.height * 0.04) + ? MediaQuery.of(context).size.width * 0.04 + : MediaQuery.of(context).size.height * 0.04, + fontFamily: GoogleFonts.jetBrainsMono().fontFamily, + ), ), ), ), diff --git a/lib/controller.dart b/lib/controller.dart new file mode 100644 index 0000000..78ccee3 --- /dev/null +++ b/lib/controller.dart @@ -0,0 +1,26 @@ +import 'package:get/get.dart'; +import 'dart:async'; + +class TextController extends GetxController { + var currentIndex = 0.obs; + List texts = [ + "Welcome to My Portfolio", + "I am an Undergraduate Student", + "I love coding", + ]; + + @override + void onInit() { + super.onInit(); + Timer.periodic( + const Duration(seconds: 5), + (timer) { + if (currentIndex.value < texts.length - 1) { + currentIndex.value++; + } else { + currentIndex.value = 0; + } + }, + ); + } +}