how can I add list of categories to my body in flutter? please I'm new to it

31 Views Asked by At

import 'package:flutter/material.dart'; import 'package:hlibrary/main.dart';

class Panel extends StatelessWidget { const Panel({Key? key});

@override Widget build(BuildContext context) {

return Stack(
  children: [
    Scaffold(
      appBar: AppBar(
        centerTitle: false,
        title: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          Text("Hlibrary",
          style: Theme.of(context).textTheme.bodyLarge!.copyWith(
            color: Colors.orangeAccent,
          ),),
          Text("Admin Panel",
          style: Theme.of(context).textTheme.titleLarge!.copyWith(
            color: Colors.orangeAccent,
          ),),
        ],)
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: (){},
        backgroundColor: Colors.orangeAccent,
        child: const Icon(Icons.add),
      ),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            const DrawerHeader(
              decoration: BoxDecoration(
                color: Color(0xFFFFB800),
              ),
              child: Text(
                'Admin Tengis',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 24,
                ),
              ),
            ),
            ListTile(
              leading: Icon(Icons.add),
              title: const Text('Add'),
              onTap: () {
                // Handle Option 1
              },
            ),
            ListTile(
              leading: Icon(Icons.list),
              title: const Text('Added files'),
              onTap: () {
                // Handle Option 2
              },
            ),
            ListTile(
              leading: Icon(Icons.arrow_back),
              title: const Text('Go back'),
              onTap: () {
                Navigator.pop(context);
              },
            ),
            // Add more ListTile for additional options
          ],
        ),
      ),
      body:  ListView(
        
      ),
    ),
  ],
);

} }

enter image description here it looks like this and I want to add categories of book when I tap the add button which is on right down corner

1

There are 1 best solutions below

0
A-E On

You can handle it that way, just make a list to store selected categories and display that list.

Regardless where are those categories are displayed in a drawer or even in the body.

      class HomeScreen extends StatefulWidget{

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
List<String> catgs = [];

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

          body: Column(
            children: [
              ListTile(
                title: Text('Science'),
                onTap: (){
                  setState((){
                    catgs.add('Science');
                  });
                },
              ),

              ListTile(
                title: Text('Sports'),
                onTap: (){
                  setState((){
                    catgs.add('Sports');
                  });
                },
              ),
              if(catgs.isNotEmpty)
              Expanded(
                child: ListView(
                  children: catgs.map((e)=> ListTile(title: Text(e),)).toList(),
                ),
              )
            ],
          )
        );
        }
}

Figure out how the idea works, and apply it.