How to use accordion custom widget

372 Views Asked by At

I used a custom widget for accordion but have no idea how it works I used classes to store the data but it comes out empty. I tried using both an index parsed through another listview and a hardcoded one but still doesn't display anything.

Accordion(
            title: receiptData.getVisitType(0),
            content: receiptData.getVisitDesc(),
          ),

title

content

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

ReceiptData receiptData = ReceiptData();

class Accordion extends StatefulWidget {
  final String title;
  final String content;

  const Accordion({Key? key, required this.title, required this.content})
      : super(key: key);
  @override
  _AccordionState createState() => _AccordionState();
}

class _AccordionState extends State<Accordion> {
  bool _showContent = false;
  @override
  Widget build(BuildContext context) {
    return Card(
      margin: const EdgeInsets.all(10),
      child: Column(children: [
        ListTile(
          title: Text(widget.title),
          onTap:(){
              setState(() {
                _showContent = !_showContent;
              });
            },
        ),
        _showContent
            ? Container(
          padding:
          const EdgeInsets.symmetric(vertical: 15, horizontal: 15),
          child: Text(widget.content),
        )
            : Container()
      ]),
    );
  }
}

main.dart

Accordion(
            title: receiptData.getVisitType(),
            content: receiptData.getVisitDesc(),
          ),

receiptClassData

import 'receiptClass.dart';

int _receiptIndex = 0;

class ReceiptData {
  final List<Receipt> _receiptdata = [
    Receipt("Physical Therapy", "Walking\nKnee jumps\nFeeding fish", "Needs to do more memory training\nto take medication 3 times per day", 23.00, 10.50, 4.0),
    Receipt("Consultation","Jogging\nGardening\nRest", "Needs more sleep and not to skip medication", 23.00, 15.50, 3.5),
    Receipt("Physical Therapy","Swimming\nWalking\nGardening", "Needs more energy so more exercise is advised", 33.00, 25.00, 5.0),
    Receipt("Consultation","nil", "Medication to be taken daily as recommended on bottle", 55.00, 45.50, 1),
    Receipt("Consultation","Walking\nGardening\nWalking Dog", "Mental health has been affected, advised to do more hobbies instead of staying at home", 33.00, 100.50, 4.5),
  ];

  String getVisitType(){
    return _receiptdata[_receiptIndex].title;
  }

  String getVisitDesc(){
    return _receiptdata[_receiptIndex].titleDesc;
  }

  String getDoctorNotes(){
    return _receiptdata[_receiptIndex].doctorNotes;
  }

  double getCFees(){
    return _receiptdata[_receiptIndex].consultationFee;
  }

  double getMFees(){
    return _receiptdata[_receiptIndex].medicationFee;
  }

  double calcTotal(){
    return _receiptdata[_receiptIndex].consultationFee + _receiptdata[_receiptIndex].medicationFee;
  }

  double getRating(){
    return _receiptdata[_receiptIndex].rating;
  }

  int getIndex(){
    return _receiptIndex;
  }


}

added the receipt class as per requested

import 'dart:ui';

class Receipt {
  String title = "";
  String titleDesc = "";
  String doctorNotes = "";
  double consultationFee = 0.0;
  double medicationFee = 0.0;
  double rating = 0.0;

  Receipt(String rs, String rtd, String rdn, double rcf, double rmf, double rr){
    String title = rs;
    String titleDesc = rtd;
    String doctorNotes = rdn;
    double consultationFee = rcf;
    double medicationFee = rmf;
    double rating = rr;
  }


}
0

There are 0 best solutions below