import 'package:flutter/material.dart'; // ================================ // MAIN APPLICATION ENTRY POINT // ================================ void main() { runApp(const MyApp()); } // ================================ // ROOT APPLICATION WIDGET // ================================ class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Complete Demo', theme: ThemeData( primarySwatch: Colors.blue, ), initialRoute: '/', routes: { '/': (context) => const HomeScreen(), '/navigation': (context) => const NavigationScreen(), '/form': (context) => const FormScreen(), '/animations': (context) => const AnimationsScreen(), '/layouts': (context) => const LayoutsScreen(), '/widgets': (context) => const WidgetsScreen(), '/tabs': (context) => const TabsScreen(), '/details': (context) => const DetailsScreen(), }, ); } } // ================================ // HOME SCREEN - MAIN MENU // ================================ class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Flutter Complete Demo'), backgroundColor: Colors.blue, ), body: ListView( padding: const EdgeInsets.all(16.0), children: [ _buildMenuCard( context, 'Navigation & Lists', 'ListView, Navigation, Drawer, Bottom Nav', Icons.list, Colors.blue, '/navigation', ), _buildMenuCard( context, 'Forms & Validation', 'TextFields, Validation, Gestures', Icons.edit, Colors.green, '/form', ), _buildMenuCard( context, 'Animations', 'Fade, Scale, Rotation Animations', Icons.animation, Colors.purple, '/animations', ), _buildMenuCard( context, 'Layouts', 'Row, Column, Stack, GridView', Icons.dashboard, Colors.orange, '/layouts', ), _buildMenuCard( context, 'Widgets & Styling', 'RichText, Images, Styling', Icons.widgets, Colors.red, '/widgets', ), _buildMenuCard( context, 'Tabs & Complex UI', 'TabController, Complex Navigation', Icons.tab, Colors.teal, '/tabs', ), ], ), ); } Widget _buildMenuCard(BuildContext context, String title, String subtitle, IconData icon, Color color, String route) { return Card( margin: const EdgeInsets.only(bottom: 16.0), child: ListTile( leading: CircleAvatar( backgroundColor: color, child: Icon(icon, color: Colors.white), ), title: Text(title, style: const TextStyle(fontWeight: FontWeight.bold)), subtitle: Text(subtitle), trailing: const Icon(Icons.arrow_forward), onTap: () => Navigator.pushNamed(context, route), ), ); } } // ================================ // NAVIGATION SCREEN // ================================ class NavigationScreen extends StatefulWidget { const NavigationScreen({super.key}); @override State createState() => _NavigationScreenState(); } class _NavigationScreenState extends State { int _selectedIndex = 0; final List items = ['Apple', 'Banana', 'Orange', 'Mango', 'Grapes']; void _onItemTapped(int index) { setState(() { _selectedIndex = index; }); Navigator.pop(context); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Navigation & Lists'), backgroundColor: Colors.blue, ), body: Column( children: [ Expanded( child: ListView.builder( itemCount: items.length, itemBuilder: (context, index) { return Card( margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), child: ListTile( leading: CircleAvatar( backgroundColor: Colors.primaries[index % Colors.primaries.length], child: Text('${index + 1}'), ), title: Text(items[index]), subtitle: const Text('Tap to view details'), trailing: const Icon(Icons.arrow_forward), onTap: () { Navigator.pushNamed(context, '/details', arguments: items[index]); }, ), ); }, ), ), Padding( padding: const EdgeInsets.all(16.0), child: ElevatedButton( onPressed: () { Navigator.pushNamed(context, '/tabs'); }, child: const Text('Go to Tabs Screen'), ), ), ], ), floatingActionButton: FloatingActionButton( onPressed: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('FAB Clicked!')), ); }, child: const Icon(Icons.add), ), bottomNavigationBar: BottomNavigationBar( items: const [ BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'), BottomNavigationBarItem(icon: Icon(Icons.settings), label: 'Settings'), ], currentIndex: _selectedIndex, onTap: _onItemTapped, ), drawer: Drawer( child: ListView( children: [ const DrawerHeader( decoration: BoxDecoration(color: Colors.blue), child: Text('Menu', style: TextStyle(color: Colors.white, fontSize: 24)), ), ListTile( leading: const Icon(Icons.home), title: const Text('Home'), onTap: () => _onItemTapped(0), ), ListTile( leading: const Icon(Icons.settings), title: const Text('Settings'), onTap: () => _onItemTapped(1), ), ], ), ), ); } } // ================================ // FORM SCREEN // ================================ class FormScreen extends StatefulWidget { const FormScreen({super.key}); @override State createState() => _FormScreenState(); } class _FormScreenState extends State { final _formKey = GlobalKey(); final _nameController = TextEditingController(); final _passwordController = TextEditingController(); final _emailController = TextEditingController(); @override void dispose() { _nameController.dispose(); _passwordController.dispose(); _emailController.dispose(); super.dispose(); } void _clearForm() { _nameController.clear(); _emailController.clear(); _passwordController.clear(); } void _submitForm() { if (_formKey.currentState!.validate()) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Form Submitted Successfully!')), ); _clearForm(); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Forms & Validation'), backgroundColor: Colors.green, ), body: Padding( padding: const EdgeInsets.all(16.0), child: Form( key: _formKey, child: Column( children: [ TextFormField( controller: _nameController, decoration: const InputDecoration( labelText: 'Name', border: OutlineInputBorder(), ), validator: (value) { if (value == null || value.isEmpty) { return 'Please enter your name'; } return null; }, ), const SizedBox(height: 16), TextFormField( controller: _emailController, decoration: const InputDecoration( labelText: 'Email', border: OutlineInputBorder(), ), validator: (value) { if (value == null || value.isEmpty) { return 'Please enter your email'; } if (!value.contains('@')) { return 'Please enter a valid email'; } return null; }, ), const SizedBox(height: 16), TextFormField( controller: _passwordController, decoration: const InputDecoration( labelText: 'Password', border: OutlineInputBorder(), ), obscureText: true, validator: (value) { if (value == null || value.isEmpty) { return 'Please enter your password'; } if (value.length < 6) { return 'Password must be at least 6 characters'; } return null; }, ), const SizedBox(height: 32), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ GestureDetector( onLongPress: _clearForm, child: Container( padding: const EdgeInsets.all(12.0), decoration: BoxDecoration( color: Colors.grey, borderRadius: BorderRadius.circular(8), ), child: const Text( 'Long Press to Clear', style: TextStyle(color: Colors.white), ), ), ), InkWell( onTap: _submitForm, child: Container( padding: const EdgeInsets.all(12.0), decoration: BoxDecoration( color: Colors.green, borderRadius: BorderRadius.circular(8), ), child: const Text( 'Submit', style: TextStyle(color: Colors.white), ), ), ), ], ), ], ), ), ), ); } } // ================================ // ANIMATIONS SCREEN // ================================ class AnimationsScreen extends StatefulWidget { const AnimationsScreen({super.key}); @override State createState() => _AnimationsScreenState(); } class _AnimationsScreenState extends State with TickerProviderStateMixin { late AnimationController _fadeController; late AnimationController _scaleController; late AnimationController _rotationController; late AnimationController _combinedController; late Animation _fadeAnimation; late Animation _scaleAnimation; late Animation _rotationAnimation; late Animation _combFadeAnimation; late Animation _combScaleAnimation; @override void initState() { super.initState(); _fadeController = AnimationController( vsync: this, duration: const Duration(seconds: 2), ); _scaleController = AnimationController( vsync: this, duration: const Duration(seconds: 2), ); _rotationController = AnimationController( vsync: this, duration: const Duration(seconds: 3), ); _combinedController = AnimationController( vsync: this, duration: const Duration(seconds: 2), ); _fadeAnimation = Tween(begin: 0.0, end: 1.0).animate(_fadeController); _scaleAnimation = Tween(begin: 0.0, end: 1.0).animate(_scaleController); _rotationAnimation = Tween(begin: 0.0, end: 1.0).animate(_rotationController); _combFadeAnimation = Tween(begin: 0.0, end: 1.0).animate(_combinedController); _combScaleAnimation = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation(parent: _combinedController, curve: Curves.bounceIn), ); _startAnimations(); } void _startAnimations() { _fadeController.forward(); _scaleController.forward(); _rotationController.repeat(); _combinedController.forward(); } @override void dispose() { _fadeController.dispose(); _scaleController.dispose(); _rotationController.dispose(); _combinedController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Animations'), backgroundColor: Colors.purple, ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ FadeTransition( opacity: _fadeAnimation, child: Container( width: 100, height: 100, color: Colors.blue, child: const Center( child: Text( 'Fade', style: TextStyle(color: Colors.white, fontSize: 16), ), ), ), ), ScaleTransition( scale: _scaleAnimation, child: Container( width: 100, height: 100, color: Colors.green, child: const Center( child: Text( 'Scale', style: TextStyle(color: Colors.white, fontSize: 16), ), ), ), ), RotationTransition( turns: _rotationAnimation, child: Container( width: 100, height: 100, color: Colors.red, child: const Center( child: Text( 'Rotate', style: TextStyle(color: Colors.white, fontSize: 16), ), ), ), ), FadeTransition( opacity: _combFadeAnimation, child: ScaleTransition( scale: _combScaleAnimation, child: Container( width: 100, height: 100, color: Colors.purple, child: const Center( child: Text( 'Combined', style: TextStyle(color: Colors.white, fontSize: 14), ), ), ), ), ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: _startAnimations, child: const Icon(Icons.replay), ), ); } } // ================================ // LAYOUTS SCREEN // ================================ class LayoutsScreen extends StatelessWidget { const LayoutsScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Layouts'), backgroundColor: Colors.orange, ), body: SingleChildScrollView( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('Row Layout:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 8), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Container(width: 50, height: 50, color: Colors.red), Container(width: 50, height: 50, color: Colors.green), Container(width: 50, height: 50, color: Colors.blue), ], ), const SizedBox(height: 20), const Text('Expanded/Flexible Row:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 8), Row( children: [ Expanded( child: Container(height: 50, color: Colors.redAccent), ), Flexible( child: Container(height: 50, color: Colors.greenAccent), ), Expanded( flex: 2, child: Container(height: 50, color: Colors.blueAccent), ), ], ), const SizedBox(height: 20), const Text('Stack Layout:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 8), Center( child: Stack( children: [ Container(width: 150, height: 150, color: Colors.blue), const Positioned( bottom: 10, right: 10, child: Icon(Icons.star, size: 30, color: Colors.yellow), ), const Positioned( top: 10, left: 10, child: Icon(Icons.favorite, size: 30, color: Colors.red), ), ], ), ), const SizedBox(height: 20), const Text('GridView:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 8), SizedBox( height: 200, child: GridView.count( crossAxisCount: 3, children: List.generate(6, (index) { return Container( margin: const EdgeInsets.all(4), color: Colors.primaries[index % Colors.primaries.length], child: Center( child: Text( 'Item $index', style: const TextStyle(color: Colors.white), ), ), ); }), ), ), ], ), ), ); } } // ================================ // WIDGETS SCREEN // ================================ class WidgetsScreen extends StatelessWidget { const WidgetsScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Widgets & Styling'), backgroundColor: Colors.red, ), body: SingleChildScrollView( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('RichText Example:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 8), RichText( text: const TextSpan( style: TextStyle(fontSize: 20, color: Colors.black), children: [ TextSpan( text: 'Bold Text ', style: TextStyle(fontWeight: FontWeight.bold), ), TextSpan(text: 'Normal Text '), TextSpan( text: 'Colored Text', style: TextStyle(color: Colors.blue), ), ], ), ), const SizedBox(height: 20), const Text('Image with Effects:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 8), Center( child: RotatedBox( quarterTurns: 0, child: Opacity( opacity: 0.8, child: ClipRRect( borderRadius: BorderRadius.circular(20), child: Container( width: 150, height: 150, color: Colors.blue, child: const Center( child: Text( 'Image\nPlaceholder', textAlign: TextAlign.center, style: TextStyle(color: Colors.white, fontSize: 16), ), ), ), ), ), ), ), const SizedBox(height: 20), const Text('ListView Example:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 8), SizedBox( height: 200, child: ListView( children: List.generate(10, (index) { return ListTile( leading: const Icon(Icons.label), title: Text('Item $index'), subtitle: Text('Subtitle for item $index'), ); }), ), ), ], ), ), ); } } // ================================ // TABS SCREEN // ================================ class TabsScreen extends StatelessWidget { const TabsScreen({super.key}); @override Widget build(BuildContext context) { return DefaultTabController( length: 3, child: Scaffold( appBar: AppBar( title: const Text('Tabs Screen'), backgroundColor: Colors.teal, bottom: const TabBar( tabs: [ Tab(icon: Icon(Icons.home), text: 'Home'), Tab(icon: Icon(Icons.settings), text: 'Settings'), Tab(icon: Icon(Icons.person), text: 'Profile'), ], ), ), body: const TabBarView( children: [ Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.home, size: 80, color: Colors.teal), SizedBox(height: 16), Text('Home Tab', style: TextStyle(fontSize: 24)), Text('Welcome to the home section'), ], ), ), Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.settings, size: 80, color: Colors.teal), SizedBox(height: 16), Text('Settings Tab', style: TextStyle(fontSize: 24)), Text('Configure your preferences'), ], ), ), Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.person, size: 80, color: Colors.teal), SizedBox(height: 16), Text('Profile Tab', style: TextStyle(fontSize: 24)), Text('View your profile information'), ], ), ), ], ), ), ); } } // ================================ // DETAILS SCREEN // ================================ class DetailsScreen extends StatelessWidget { const DetailsScreen({super.key}); @override Widget build(BuildContext context) { final String item = ModalRoute.of(context)!.settings.arguments as String; return Scaffold( appBar: AppBar( title: const Text('Details Screen'), backgroundColor: Colors.indigo, ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 100, height: 100, decoration: BoxDecoration( color: Colors.indigo, borderRadius: BorderRadius.circular(50), ), child: const Icon( Icons.info, size: 50, color: Colors.white, ), ), const SizedBox(height: 20), Text( 'Selected Item:', style: Theme.of(context).textTheme.headlineSmall, ), const SizedBox(height: 10), Text( item, style: Theme.of(context).textTheme.headlineMedium?.copyWith( color: Colors.indigo, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 30), ElevatedButton( onPressed: () => Navigator.pop(context), child: const Text('Go Back'), ), ], ), ), ); } }