simple_expander 0.1.10 copy "simple_expander: ^0.1.10" to clipboard
simple_expander: ^0.1.10 copied to clipboard

This package is composed of a simple expansion tile that I made myself because the existing ones didn't satisfied me for a specific project I had

example/example.md

import 'dart:developer';

import 'package:example/simple_object.dart';
import 'package:flutter/material.dart';

import 'package:simple_expander/simple_expander.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(title: 'Test page for SimpleExpander'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  final List<SimpleObject> testValues = [
    SimpleObject(id: 1, name: "name name name name name name name name name name name name name name name name name ", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 2, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 3, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 4, name: "name", secondName: "secondName", moment: DateTime.now()),
  ];

  final List<SimpleObject> otherValues = [
    SimpleObject(id: 1, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 2, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 1, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 2, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 1, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 2, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 1, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 2, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 1, name: "name", secondName: "secondName", moment: DateTime.now()),
    SimpleObject(id: 2, name: "name", secondName: "secondName", moment: DateTime.now()),
  ];

  final List<SimpleObject> moreValues = [
    SimpleObject(id: 1, name: "name", secondName: "secondName secondName secondName secondName secondName secondName secondName secondName secondName secondName ", moment: DateTime.now()),
    SimpleObject(id: 2, name: "name", secondName: "secondName", moment: DateTime.now()),
  ];


  _showPopupMenu(RelativeRect pressPosition, SimpleObject simpleObject) async {
    await showMenu(
      context: context,
      position: pressPosition,
      items: <PopupMenuItem<String>>[
        PopupMenuItem<String>(
          value: 'Modifier',
          onTap: () async {
            log('Message from popup menu item MODIFIER for simple object with id : ${simpleObject.id}');
          },
          child: const Text('Modifier'),
        ),
        PopupMenuItem<String>(
            value: 'Supprimer',
            onTap: () async {
              log('Message from popup menu item SUPPRIMER for simple object with id : ${simpleObject.id}');
            },
            child: const Text('Supprimer')
        ),
      ],
      elevation: 8.0,
    );
  }




  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        backgroundColor: Colors.grey,
      ),
      body: Container(
        padding: const EdgeInsets.all(20),
        width: MediaQuery.of(context).size.width,
        child: SingleChildScrollView(
          child: Column(
            children: [
              const SizedBox(height: 100,),

              SimpleExpander(
                headerString: "Header title",
                initiallyExpanded: true,
                baseHeight: 90,
                tiles: moreValues.map((oneSimpleObject) => SimpleExpanderTile(
                  title: oneSimpleObject.name,
                  subtitle: oneSimpleObject.secondName,
                  onTap: () async {
                    log('onTap function for simple_expander_tile with id : ${oneSimpleObject.id}');
                  },
                  trailing: IconButton(
                    icon: const Icon(Icons.people, size: 30),
                    onPressed: () {
                      log("onPressed function has been triggered on tile trailing n°${oneSimpleObject.id}");
                    },
                  ),
                  showPopupMenuFunction: (RelativeRect pressPosition) {
                    _showPopupMenu(pressPosition, oneSimpleObject); // CAN BE CALLED EVEN IF NOT ASYNC
                  }
                )).toList(),
              ),

              const SizedBox(height: 20,),

              SimpleExpander(
                headerString: "Header title Header title Header title Header title Header title Header title Header title ",
                headerColor: Colors.deepPurpleAccent,
                headerTrailing: IconButton(
                  icon: const Icon(Icons.access_alarm, color: Colors.white, size: 25),
                  onPressed: () {
                    log("Header trailing widget has been pressed !!");
                  },
                ),
                tiles: testValues.map((oneSimpleObject) => SimpleExpanderTile(
                  title: oneSimpleObject.name,
                  subtitle: oneSimpleObject.secondName,
                  onTap: () async {
                    log('onTap function for simple_expander_tile with id : ${oneSimpleObject.id}');
                  },
                )).toList(),
              ),

              const SizedBox(height: 20,),

              SimpleExpander(
                headerString: "Header title",
                durationOnTiles: true,
                curve: 5,
                milliseconds: 100,
                tiles: otherValues.map((oneSimpleObject) => SimpleExpanderTile(
                  title: oneSimpleObject.name,
                  subtitle: null,
                  onTap: () async {
                    log('onTap function for simple_expander_tile with id : ${oneSimpleObject.id}');
                  },
                  tileColor: Colors.greenAccent,
                )).toList(),
              ),
            ],
          ),
        ),
      )
    );
  }
}

2
likes
150
points
83
downloads

Publisher

verified publisherlaurentstienon.com

Weekly Downloads

This package is composed of a simple expansion tile that I made myself because the existing ones didn't satisfied me for a specific project I had

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT-0 (license)

Dependencies

flutter, font_awesome_flutter

More

Packages that depend on simple_expander