Flutter with Praveen: Add Tabs with Image & Text in Your App

import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter with Praveen',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TabScreen(),
);
}
}

class TabScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(16.0),
child: DefaultTabController(
length: 2, // 2 Tabs (Login & Register)
child: Column(
children: [
// 📌 1. Heading Text
Text(
"Flutter with Praveen",
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
SizedBox(height: 10),

// 📌 2. Image
ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image.network(
"https://images.unsplash.com/photo-1575936123452-b67c3203c357?fm=jpg&q=60&w=3000&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8aW1hZ2V8ZW58MHx8MHx8fDA%3D", // Replace with your image
height: 150,
width: double.infinity,
fit: BoxFit.cover,
),
),
SizedBox(height: 20),

// 📌 3. TabBar
Container(
decoration: BoxDecoration(
color: Colors.blue[100],
borderRadius: BorderRadius.circular(20),
),
child: TabBar(
indicator: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(20),
),
labelColor: Colors.white,
unselectedLabelColor: Colors.black,
tabs: [
Tab(text: "Login"),
Tab(text: "Register"),
],
),
),
SizedBox(height: 20),

// 📌 4. TabBarView (Inside Screen)
Expanded(
child: TabBarView(
children: [
LoginScreen(),
RegisterScreen(),
],
),
),
],
),
),
),
);
}
}

// 📌 Login Screen UI
class LoginScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
decoration: InputDecoration(
labelText: "Email",
border: OutlineInputBorder(),
),
),
SizedBox(height: 10),
TextField(
obscureText: true,
decoration: InputDecoration(
labelText: "Password",
border: OutlineInputBorder(),
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {},
child: Text("Login"),
),
],
),
);
}
}

// 📌 Register Screen UI
class RegisterScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
decoration: InputDecoration(
labelText: "Full Name",
border: OutlineInputBorder(),
),
),
SizedBox(height: 10),
TextField(
decoration: InputDecoration(
labelText: "Email",
border: OutlineInputBorder(),
),
),
SizedBox(height: 10),
TextField(
obscureText: true,
decoration: InputDecoration(
labelText: "Password",
border: OutlineInputBorder(),
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {},
child: Text("Register"),
),
],
),
);
}
}










 

Comments

Popular posts from this blog

Unlocking the Power of OOP: A Beginner's Guide to Objects, Encapsulation, Inheritance, Abstraction, and Polymorphism

HTTP GET Response in Flutter

Building a Flutter Firebase Firestore CRUD App