Created with <3 with dartpad.dev.
Created
November 26, 2022 06:45
-
-
Save Bharathh-Raj/a9706b9fc14436afe0f989cb8e0e1a21 to your computer and use it in GitHub Desktop.
powerful-illusion-0942
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
home: TextCarousal(), | |
); | |
} | |
} | |
class TextCarousal extends StatefulWidget { | |
const TextCarousal({Key? key}) : super(key: key); | |
@override | |
State<TextCarousal> createState() => _TextCarousalState(); | |
} | |
class _TextCarousalState extends State<TextCarousal> | |
with SingleTickerProviderStateMixin<TextCarousal> { | |
final PageController pageController = PageController(); | |
late TabController tabController; | |
static const textList = [ | |
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', | |
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', | |
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' | |
]; | |
@override | |
void initState() { | |
tabController = TabController(length: textList.length, vsync: this); | |
pageController.addListener(_updateTabController); | |
super.initState(); | |
} | |
@override | |
void dispose() { | |
pageController.removeListener(_updateTabController); | |
super.dispose(); | |
} | |
void _updateTabController() { | |
tabController.index = pageController.page!.toInt(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.grey, | |
body: Center( | |
child: Container( | |
height: 220, | |
color: Colors.white, | |
child: Column( | |
children: [ | |
SizedBox( | |
height: 160, | |
width: 250, | |
child: PageView.builder( | |
controller: pageController, | |
itemCount: textList.length, | |
itemBuilder: (context, index) => Center( | |
child: Text( | |
textList[index], | |
textAlign: TextAlign.center, | |
style: Theme.of(context) | |
.textTheme | |
.bodyMedium! | |
.copyWith(color: Colors.black), | |
), | |
)), | |
), | |
TabPageSelector( | |
controller: tabController, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment