Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/text-switcher/text_switcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class TextSwitcher extends StatefulWidget {
final List<String> texts; // Accepting a list of texts

TextSwitcher({Key? key, required this.texts}) : super(key: key);

@override
_TextSwitcherState createState() => _TextSwitcherState();
}

class _TextSwitcherState extends State<TextSwitcher> {
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<double> animation) {
final offsetAnimation = Tween<Offset>(
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<int>(_currentIndex),
style: GoogleFonts.acme(fontSize: 32.0, color: Colors.white),
),
),
),
);
}
}

32 changes: 32 additions & 0 deletions lib/text-switcher/text_swithcer_exmaple.dart
Original file line number Diff line number Diff line change
@@ -0,0 +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<TextSwitcherExample> {

@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."])
),
);
}
}