0

Problem is when clicking on textfield the keyboard appears laggily. it does not appears in instant like it does on whatspp or any other application no matter how big size of application is , it will appear instantly without any lag. It lags in my flutter app only.

import 'package:flutter/material.dart';

// --- 1. Color and Constant Definitions ---
const Color kPrimaryColor = Color(0xFF282C5C); // Deep Blue/Indigo
const Color kBackgroundColor = Color(0xFFF7F9FC); // Very Light Gray
const Color kAccentGreen = Color(0xFF4CAF50);
const Color kAccentRed = Color(0xFFF44336);
const Color kAccentAmber = Color(0xFFFFC107);
const Color kAccentBlueLight = Color(0xFF3B82F6);
const Color kCardColor = Colors.white;



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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Enquiry Management',
      theme: ThemeData(
        primaryColor: kPrimaryColor,
        scaffoldBackgroundColor: kBackgroundColor,
        appBarTheme: const AppBarTheme(
          backgroundColor: kPrimaryColor,
          foregroundColor: Colors.white,
          elevation: 0,
        ),
        fontFamily: 'Inter',
      ),
      home: const EnquiryScreen(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(

      resizeToAvoidBottomInset: false,
     
      body: GestureDetector(
        onTap: () {
          FocusScope.of(context).unfocus();
        },
        child: CustomScrollView(

          physics: const ClampingScrollPhysics(),
          slivers: [
            // Tab-like buttons (Filters)
            SliverToBoxAdapter(
              child: SingleChildScrollView(
                scrollDirection: Axis.horizontal,
                padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
                child: Row(
                  children: [
                    _FilterButton('All (5182)', kAccentRed, isActive: true),
                    _FilterButton('Registration Done (2186)', kPrimaryColor),
                    _FilterButton('Visited (1410)', kAccentBlueLight),
                    _FilterButton('In Progress (1265)', kAccentGreen),
                    _FilterButton('Negative (170)', Colors.grey),
                  ],
                ),
              ),
            ),

            // Action/Filter Bar
            SliverToBoxAdapter(
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 16.0),
                child: Row(
                  children: [
                    Expanded(
                      child: TextField(
                        decoration: InputDecoration(
                          hintText: 'Search Name/Phone...',
                          prefixIcon: const Icon(Icons.search, color: kPrimaryColor),
                          border: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(12),
                              borderSide: BorderSide.none
                          ),
                          filled: true,
                          fillColor: kCardColor,
                          contentPadding: const EdgeInsets.symmetric(vertical: 10),
                        ),

                        onTap: () {},
                      ),
                    ),
                    const SizedBox(width: 12),
                    ElevatedButton.icon(
                      onPressed: () {},
                      icon: const Icon(Icons.add, size: 20),
                      label: const Text('New'),
                      style: ElevatedButton.styleFrom(
                        backgroundColor: kAccentGreen,
                        foregroundColor: Colors.white,
                        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
                        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            const SliverToBoxAdapter(child: SizedBox(height: 16)),

            // Enquiry List
            SliverList(
              delegate: SliverChildBuilderDelegate(
                    (context, index) {
                  final enquiries = [
                    _EnquiryListItem(
                      name: 'Amandeep Kaur',
                      phone: '98xxxxxx91',
                      course: 'Autocad',
                      fees: '6500',
                      source: 'Visited',
                      status: 'Hot Lead',
                      statusColor: kAccentGreen,
                    ),
                    _EnquiryListItem(
                      name: 'Tanya Sharma',
                      phone: '96xxxxxx51',
                      course: 'Photoshop',
                      fees: '11500',
                      source: 'Online',
                      status: 'In Process',
                      statusColor: kAccentAmber,
                    ),
                    _EnquiryListItem(
                      name: 'Rajesh Kumar',
                      phone: '91xxxxxx02',
                      course: 'Data Science',
                      fees: '25000',
                      source: 'Referred',
                      status: 'Registration Done',
                      statusColor: kPrimaryColor,
                    ),
                    _EnquiryListItem(
                      name: 'Priya Verma',
                      phone: '93xxxxxx45',
                      course: 'Web Development',
                      fees: '18000',
                      source: 'Walk-in',
                      status: 'Visited',
                      statusColor: kAccentBlueLight,
                    ),
                    _EnquiryListItem(
                      name: 'Gaurav Singh',
                      phone: '97xxxxxx88',
                      course: 'Graphic Design',
                      fees: '9000',
                      source: 'Online',
                      status: 'Negative',
                      statusColor: Colors.grey,
                    ),
                  ];
                  return Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 16.0),
                    child: enquiries[index],
                  );
                },
                childCount: 5,
              ),
            ),
            const SliverToBoxAdapter(child: SizedBox(height: 12)),
          ],
        ),
      ),
    );
  }
}

// Helper Widget for Filter Buttons
class _FilterButton extends StatelessWidget {
  final String label;
  final Color color;
  final bool isActive;

  const _FilterButton(this.label, this.color, {this.isActive = false});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(right: 8.0),
      child: ElevatedButton(
        onPressed: () {},
        style: ElevatedButton.styleFrom(
          backgroundColor: color,
          foregroundColor: Colors.white,
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
          elevation: 2,
        ),
        child: Text(label, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600)),
      ),
    );
  }
}

// Helper Widget for Enquiry List Items
class _EnquiryListItem extends StatelessWidget {
  final String name;
  final String phone;
  final String course;
  final String fees;
  final String source;
  final String status;
  final Color statusColor;

  const _EnquiryListItem({
    required this.name,
    required this.phone,
    required this.course,
    required this.fees,
    required this.source,
    required this.status,
    required this.statusColor,
  });

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: const EdgeInsets.only(bottom: 12),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      elevation: 2,
      child: ListTile(
        contentPadding: const EdgeInsets.all(12),
        leading: CircleAvatar(
          backgroundColor: kPrimaryColor,
          child: Text(name[0], style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
        ),
        title: Text(name, style: TextStyle(fontWeight: FontWeight.bold, color: kPrimaryColor)),
        subtitle: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text('📞 $phone | Course: $course', style: const TextStyle(fontSize: 13)),
            Text('Fees: ₹$fees | Source: $source', style: const TextStyle(fontSize: 13)),
          ],
        ),
        trailing: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
              decoration: BoxDecoration(
                color: statusColor.withOpacity(0.15),
                borderRadius: BorderRadius.circular(10),
              ),
              child: Text(
                status,
                style: TextStyle(color: statusColor, fontSize: 11, fontWeight: FontWeight.bold),
              ),
            ),
            const SizedBox(height: 4),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Icon(Icons.edit, size: 18, color: kAccentBlueLight),
                const SizedBox(width: 8),
                Icon(Icons.delete, size: 18, color: kAccentRed),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

i have sent the whole code dont know what is making it lag. if anyone encounter same issue do tell.

2
  • did u try creating new flutter project with a blank screen and a text field in the center and see how does that perform? Commented Oct 30 at 7:50
  • Did you try to compile in release mode? Or have you been testing debug all along? Commented Nov 4 at 14:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.