Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- String selectedChoiceA = "";
- String selectedChoiceB = "";
- List<String> dataForChoiceA = ["Item A1", "Item A2", "Item A3"];
- List<String> dataForChoiceB = ["Item B1", "Item B2", "Item B3"];
- List<String> filteredList = [];
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- appBar: AppBar(
- title: Text('ChoiceChips Example'),
- ),
- body: Column(
- children: [
- Wrap(
- children: [
- ChoiceChip(
- label: Text('Choice A'),
- selected: selectedChoiceA == 'Choice A',
- onSelected: (selected) {
- setState(() {
- selectedChoiceA = selected ? 'Choice A' : '';
- // Memfilter daftar berdasarkan pilihan Choice A
- if (selectedChoiceA == 'Choice A') {
- filteredList = dataForChoiceA;
- } else {
- filteredList = [];
- }
- });
- },
- ),
- ChoiceChip(
- label: Text('Choice B'),
- selected: selectedChoiceB == 'Choice B',
- onSelected: (selected) {
- setState(() {
- selectedChoiceB = selected ? 'Choice B' : '';
- // Memfilter daftar berdasarkan pilihan Choice B
- if (selectedChoiceB == 'Choice B') {
- filteredList = dataForChoiceB;
- } else {
- filteredList = [];
- }
- });
- },
- ),
- ],
- ),
- SizedBox(height: 20),
- Expanded(
- child: ListView.builder(
- itemCount: filteredList.length,
- itemBuilder: (context, index) {
- return ListTile(
- title: Text(filteredList[index]),
- );
- },
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement