skip to Main Content
            ? AppBar(
                backgroundColor: Colors.white,
                title: TextField(
                    onChanged: (value) {
                      print("000$value");
                      setState(() {
                        if (value.isNotEmpty) {
                          serchlist = [];
                          for (int u = 0; u < notedata.length; u++) {
                            String title = notedata[u]['TITLE'];
                            String subject = notedata[u]['NOTES'];
                            int color = notedata[u]['COLORS'];
                            if (title
                                    .toLowerCase()
                                    .contains(value.toLowerCase()) ||
                                subject
                                    .toUpperCase()
                                    .contains(value.toUpperCase()) ) {
                              print("111$title");
                              serchlist.add(notedata[u]);
                            } else {}
                          }
                        } else {
                          serchlist = notedata;
                        }
                      });
                    },
                    autofocus: true,
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: "🔍 search",
                      suffixIcon: IconButton(
                          onPressed: () {
                            setState(() {
                              issearch = false;
                            });
                          },
                          icon: Icon(
                            Icons.close,
                            color: Colors.black,
                          )),
                    )),
              )
            : AppBar(
                leading: IconButton(onPressed: () {}, icon: Icon(Icons.menu)),
                actions: [
                  IconButton(
                      onPressed: () {
                        setState(() {
                          issearch = true;
                        });
                      },
                      icon: Icon(Icons.search_sharp)),
                  IconButton(onPressed: () {}, icon: Icon(Icons.more_vert)),
                ],
                backgroundColor: Colors.orange.shade500,
                elevation: 5,
                title: Text("Notes",
                    style: TextStyle(fontFamily: "regular", fontSize: 26))),

how I pass colors of container in search method.

2

Answers


  1. edit your code checkout bellow code.

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key, required this.title});
      final String title;
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      bool issearch = true;
      List<Map> serchlist = [];
      List<int> colorlist = [];
      List<Map> notedata = [
        {
          'TITLE': "yellow",
          'NOTES': "notes1",
          'COLORS': 4,
        },
        {
          'TITLE': "blue",
          'NOTES': "notes1",
          'COLORS': 3,
        },
        {
          'TITLE': "red",
          'NOTES': "notes1",
          'COLORS': 2,
        }
      ];
    
      @override
      void initState() {
        super.initState();
        serchlist = notedata;
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: issearch
              ? AppBar(
                  backgroundColor: Colors.white,
                  title: TextField(
                      onChanged: (value) {
                        setState(() {
                          if (value.isNotEmpty) {
                            serchlist = [];
                            for (int u = 0; u < notedata.length; u++) {
                              String title = notedata[u]['TITLE'];
                              String subject = notedata[u]['NOTES'];
                              int color = notedata[u]['COLORS'];
                              if (title
                                      .toLowerCase()
                                      .contains(value.toLowerCase()) ||
                                  subject
                                      .toUpperCase()
                                      .contains(value.toUpperCase()) ||
                                  color.toString().contains(value.toLowerCase())) {
                                serchlist.add(notedata[u]);
                                colorlist.add(color);
                              }
                            }
                          } else {
                            serchlist = notedata;
                          }
                          setState(() {});
                        });
                      },
                      autofocus: true,
                      decoration: InputDecoration(
                        icon: const Text("🔍"),
                        border: InputBorder.none,
                        hintText: " search",
                        suffixIcon: IconButton(
                            onPressed: () {
                              setState(() {
                                issearch = false;
                              });
                            },
                            icon: const Icon(
                              Icons.close,
                              color: Colors.black,
                            )),
                      )),
                )
              : AppBar(
                  leading:
                      IconButton(onPressed: () {}, icon: const Icon(Icons.menu)),
                  actions: [
                    IconButton(
                        onPressed: () {
                          setState(() {
                            issearch = true;
                          });
                        },
                        icon: const Icon(Icons.search_sharp)),
                    IconButton(onPressed: () {}, icon: const Icon(Icons.more_vert)),
                  ],
                  backgroundColor: Colors.orange.shade500,
                  elevation: 5,
                  title: const Text("Notes",
                      style: TextStyle(fontFamily: "regular", fontSize: 26))),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              ListView.builder(
                shrinkWrap: true,
                itemCount: serchlist.length,
                itemBuilder: ((context, index) {
                  return Card(
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text("TITLE ${serchlist[index]['TITLE'] ?? ""}"),
                          Text(
                              "NOTES ${serchlist[index]['NOTES'] as String ?? ""}"),
                          Text("COLORS ${serchlist[index]['COLORS'] as int ?? 0}"),
                        ],
                      ),
                    ),
                  );
                }),
              )
            ],
          ),
        );
      }
    }
    
    Login or Signup to reply.
  2. Send any of the three parameter through search and get result from the server

    As from the problem I understand user can search by colour,subject or titles simply let user put any of the things as input and you can search from the database which ever parameter it matches and then return it to the API or user. But make sure you have implemented this on server side.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search