From cf782cf16774bf1be83d2355db0f1b5b7f049e68 Mon Sep 17 00:00:00 2001 From: Kaleab Wondwossen <140511588+Kaleab-Wondwossen@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:30:38 +0300 Subject: [PATCH 1/6] Create folder text-switcher --- lib/text-switcher | 1 + 1 file changed, 1 insertion(+) create mode 100644 lib/text-switcher diff --git a/lib/text-switcher b/lib/text-switcher new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/lib/text-switcher @@ -0,0 +1 @@ + From 570df496777023504547cdded49ea9ac6f27976c Mon Sep 17 00:00:00 2001 From: Kaleab Wondwossen <140511588+Kaleab-Wondwossen@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:54:53 +0300 Subject: [PATCH 2/6] Delete lib/text-switcher to make it a folder --- lib/text-switcher | 1 - 1 file changed, 1 deletion(-) delete mode 100644 lib/text-switcher diff --git a/lib/text-switcher b/lib/text-switcher deleted file mode 100644 index 8b13789..0000000 --- a/lib/text-switcher +++ /dev/null @@ -1 +0,0 @@ - From cdf403d5db2a038991e55d46c780f01edc9ee91b Mon Sep 17 00:00:00 2001 From: Kaleab Wondwossen <140511588+Kaleab-Wondwossen@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:55:53 +0300 Subject: [PATCH 3/6] Create text_switcher.dart in the text-switcher folder --- lib/text-switcher/text_switcher.dart | 1 + 1 file changed, 1 insertion(+) create mode 100644 lib/text-switcher/text_switcher.dart diff --git a/lib/text-switcher/text_switcher.dart b/lib/text-switcher/text_switcher.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/lib/text-switcher/text_switcher.dart @@ -0,0 +1 @@ + From 359aa8bca706ba64f9d8922f085a4a0436165611 Mon Sep 17 00:00:00 2001 From: Kaleab Wondwossen <140511588+Kaleab-Wondwossen@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:56:28 +0300 Subject: [PATCH 4/6] added implementations for text_switcher.dart --- lib/text-switcher/text_switcher.dart | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/text-switcher/text_switcher.dart b/lib/text-switcher/text_switcher.dart index 8b13789..69b2eb1 100644 --- a/lib/text-switcher/text_switcher.dart +++ b/lib/text-switcher/text_switcher.dart @@ -1 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; + +class TextSwitcher extends StatefulWidget { + final List texts; // Accepting a list of texts + + TextSwitcher({Key? key, required this.texts}) : super(key: key); + + @override + _TextSwitcherState createState() => _TextSwitcherState(); +} + +class _TextSwitcherState extends State { + int _currentIndex = 0; + + void _switchText() { + setState(() { + _currentIndex = (_currentIndex + 1) % widget.texts.length; // Use widget.texts + }); + } + + @override + Widget build(BuildContext context) { + return Container( + color: const Color.fromARGB(255, 34, 34, 34), // Background color + alignment: Alignment.center, // Center the text in the container + child: GestureDetector( + onTap: _switchText, + child: AnimatedSwitcher( + duration: Duration(seconds: 1), + transitionBuilder: (Widget child, Animation animation) { + final offsetAnimation = Tween( + begin: Offset(1.0, 0.0), + end: Offset(0.0, 0.0), + ).animate(animation); + return SlideTransition(position: offsetAnimation, child: child); + }, + child: Text( + widget.texts[_currentIndex], // Accessing the texts from widget + key: ValueKey(_currentIndex), + style: GoogleFonts.acme(fontSize: 32.0, color: Colors.white), + ), + ), + ), + ); + } +} From 809042da1906ed0750f45e486a3c15f937debe73 Mon Sep 17 00:00:00 2001 From: Kaleab Wondwossen <140511588+Kaleab-Wondwossen@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:57:13 +0300 Subject: [PATCH 5/6] Create text_swithcer_exmaple.dart in the text_switcher folder --- lib/text-switcher/text_swithcer_exmaple.dart | 1 + 1 file changed, 1 insertion(+) create mode 100644 lib/text-switcher/text_swithcer_exmaple.dart diff --git a/lib/text-switcher/text_swithcer_exmaple.dart b/lib/text-switcher/text_swithcer_exmaple.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/lib/text-switcher/text_swithcer_exmaple.dart @@ -0,0 +1 @@ + From c43f9be56e1254646de615f17d8cd765cc83ef86 Mon Sep 17 00:00:00 2001 From: Kaleab Wondwossen <140511588+Kaleab-Wondwossen@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:57:52 +0300 Subject: [PATCH 6/6] implemented the text_switch class on text_swithcer_exmaple.dart --- lib/text-switcher/text_swithcer_exmaple.dart | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/text-switcher/text_swithcer_exmaple.dart b/lib/text-switcher/text_swithcer_exmaple.dart index 8b13789..90d91e1 100644 --- a/lib/text-switcher/text_swithcer_exmaple.dart +++ b/lib/text-switcher/text_swithcer_exmaple.dart @@ -1 +1,32 @@ +import 'package:flutter/material.dart'; +import 'package:getchereta/measure/consts.dart'; +import 'package:getchereta/screens/eg2.dart'; +import 'package:google_fonts/google_fonts.dart'; + +class TextSwitcherExample extends StatefulWidget { + @override + _TextSwitcherExampleState createState() => _TextSwitcherExampleState(); +} + +class _TextSwitcherExampleState extends State { + + @override + Widget build(BuildContext context) { + AppSizes.init(context); + + return Scaffold( + backgroundColor: const Color.fromARGB(255, 34, 34, 34), + appBar: AppBar(title: Center( + child: Text("Text Switcher Example", style: GoogleFonts.acme( + color: Colors.white, + fontSize: AppSizes.secondaryFontSize, + fontWeight: FontWeight.bold + ),), + ), backgroundColor: Color.fromARGB(255, 34, 34, 34), automaticallyImplyLeading: false,), + body: Center( + child: TextSwitcher(texts: ["Hello", "World", "Flutter", "Animations", "Open Source."]) + ), + ); + } +}