Text field isnt changing to editable when button is pressed. Flutter/Dart

Viewed 27

The "title" text field is supposed to change to editable when the edit button on the appbar is pressed, but it doesnt seem to work when.

Your help is much appreciated, thanks

here is my code

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class viewLossEvent extends StatefulWidget {

  String code,
      title,
      orgUnit,
      riskOfficer,
      natureOfEvent,
      islamicBusiness,
      shariahRelated,
      incidentType,
      operationalRiskLossType,
      countryOfEvent,
      stateOfEvent,
      districtOfEvent,
      modusOperandi,
      factOfIncident,
  //Status Approval and Validation
      status,
      incidentOwner,
      rejectionComment,
      ormdRec,
      reasonNotValid,
  //Incident Categorization
      busline1,
      busline2,
      busline3,
      proServ,
      delChannel,
      causCat1,
      causCat2,
      causCat3,
      causCatOth,
      eventcat1,
      eventcat2,
      eventcat3,
      boundOthRisk,
      payInst,
      cardBrand,
      payChan,
      cardType,
      busAct,
      accType,
      depRisk,
      riskAss,
      riskRate,
  //Fraud Related Information
      possfraud,
      iADRD,
      iADF,
      iADC,
  //Incident Dates
      discDate,
      discTime,
      occDate,
      occTime,
      resDate,
      resTime,
      subBNMDate,
      dateIncRep,
      recDate,
      closeDate,
  //Incident Loss Data
      grossLoss,
      recoveryAmmount,
      netLoss,
      recoveryEC,
      contingentLia;


  viewLossEvent(
      {this.code,
      this.title,
      this.orgUnit,
      this.riskOfficer,
      this.natureOfEvent,
      this.islamicBusiness,
      this.shariahRelated,
      this.incidentType,
      this.operationalRiskLossType,
      this.countryOfEvent,
      this.stateOfEvent,
      this.districtOfEvent,
      this.modusOperandi,
      this.factOfIncident,
      this.status,
      this.incidentOwner,
      this.rejectionComment,
      this.ormdRec,
      this.reasonNotValid,
      this.busline1,
      this.busline2,
      this.busline3,
      this.proServ,
      this.delChannel,
      this.causCat1,
      this.causCat2,
      this.causCat3,
        this.causCatOth,
      this.eventcat1,
      this.eventcat2,
      this.eventcat3,
      this.boundOthRisk,
      this.payInst,
      this.cardBrand,
      this.payChan,
      this.cardType,
      this.busAct,
      this.accType,
      this.depRisk,
      this.riskAss,
      this.riskRate,
      this.possfraud,
      this.iADRD,
      this.iADF,
      this.iADC,
      this.discDate,
      this.discTime,
      this.occDate,
      this.occTime,
      this.resDate,
      this.resTime,
      this.subBNMDate,
      this.dateIncRep,
      this.recDate,
      this.closeDate,
      this.grossLoss,
      this.recoveryAmmount,
      this.netLoss,
      this.recoveryEC,
      this.contingentLia});

  @override
  State<viewLossEvent> createState() => _viewLossEventState();
}

class _viewLossEventState extends State<viewLossEvent> {

  bool isReadOnly = true;

  int _selectedIndex = 0;

  void _navigateBottomBar(int index){
    setState(() {
      _selectedIndex = index;
    });
  }

  List<Widget> _pages = [];

  void initState() {

    super.initState();

    _pages = [
      Container(
        child: SingleChildScrollView(
          child: Column(
            children: [
              //Main Info
              ListTileTheme(
                tileColor: Colors.grey,
                child: ExpansionTile(
                  title: Text(
                      'Main Info',
                      style: GoogleFonts.poppins(textStyle: const TextStyle(
                        color: Colors.black,
                        fontWeight: FontWeight.bold,
                        fontSize: 20,))
                  ),
                  children: [
                    //Fields
                    ListTileTheme(
                      tileColor: Colors.white,
                      child: ListTile(
                        title: Text('Code : ${widget.code}',
                          style: GoogleFonts.poppins(textStyle: const TextStyle(
                            fontWeight: FontWeight.normal,
                            fontSize: 20,
                          ),),),
                      ),
                    ),
                    ListTileTheme(
                      tileColor: Colors.white,
                      child: ListTile(
                        leading: Text(
                          'Title : ',
                          style: TextStyle(
                              fontSize: 20.0,
                              color: Colors.black,
                            fontWeight: FontWeight.bold
                          ),
                        ),
                        title: TextField(
                          readOnly: isReadOnly,
                          decoration: InputDecoration(
                            hintStyle: TextStyle(fontSize: 20.0, color: Colors.black),
                            hintText: '${widget.title}',
                            border: InputBorder.none,
                          ),
                        ),
                      ),
                    ),],),
      Container(
        child: SingleChildScrollView(
          child: Column(
            children: [
              //Shariah Details
              ListTileTheme(
                tileColor: Colors.grey,
                child: ExpansionTile(
                  title: Text(
                      'LE Attachment',
                      style: GoogleFonts.poppins(textStyle: const TextStyle(
                        color: Colors.black,
                        fontWeight: FontWeight.bold,
                        fontSize: 20,))
                  ),
                  children: [
                    //Fields

                  ],),
              ),
            ],
          ),
        ),
      ),
      Container(
        child: SingleChildScrollView(
          child: Column(
            children: [
              //Shariah Details
              ListTileTheme(
                tileColor: Colors.grey,
                child: ExpansionTile(
                  title: Text(
                      'LE Action',
                      style: GoogleFonts.poppins(textStyle: const TextStyle(
                        color: Colors.black,
                        fontWeight: FontWeight.bold,
                        fontSize: 20,))
                  ),
                  children: [
                    //Fields

                  ],),
              ),
            ],
          ),
        ),
      ),
      Container(
        child: SingleChildScrollView(
          child: Column(
            children: [
              //Shariah Details
              ListTileTheme(
                tileColor: Colors.grey,
                child: ExpansionTile(
                  title: Text(
                      'Compliance Incident',
                      style: GoogleFonts.poppins(textStyle: const TextStyle(
                        color: Colors.black,
                        fontWeight: FontWeight.bold,
                        fontSize: 20,))
                  ),
                  children: [
                    //Fields

                  ],),
              ),
            ],
          ),
        ),
      ),
    ];
  }




  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: const Color(0xFF002d62),
        title: Text('${widget.code}',
            style: GoogleFonts.sora(
              textStyle: const TextStyle(
                fontSize: 25,
                fontWeight: FontWeight.w500,
              ),
            )),
            actions: [
          IconButton(
            icon: Icon(Icons.edit),
            onPressed: () {
              setState(() {
                isReadOnly = !isReadOnly;
              });
            },
          ),
        ],
      ),
      body: _pages[_selectedIndex],
      bottomNavigationBar: BottomNavigationBar(
          onTap: _navigateBottomBar,
          currentIndex: _selectedIndex,
        type: BottomNavigationBarType.fixed,
          items: [
        BottomNavigationBarItem(icon: Icon(Icons.home), label: 'General'),
        BottomNavigationBarItem(icon: Icon(Icons.balance), label: 'LE Shariah'),
        BottomNavigationBarItem(icon: Icon(Icons.attachment), label: 'LE Attachment'),
        BottomNavigationBarItem(icon: Icon(Icons.call_to_action), label: 'LE Action'),
        BottomNavigationBarItem(icon: Icon(Icons.person_pin_circle), label: 'Compliance Incident'),
      ]),
    );
  }
}

heres a picture for better understanding

enter image description here

the field "title" that is showing "test_01" is supposed to change to an editable text field when the edit button ive placed on the appbar is pressed but it isnt :( if there are any fixes or changes to my code please do tell. Thanks

1 Answers

Don't use textfield in leading place.leading is place for icon that does not do any moving activity.you can't use textfield, chackbox and onther widget in place of leading.

Related