Chip

Chip

Chip({ avatar, label })

açıklama

İçerisinde bir ikon yada resim, text alan etkileşimli widget.

konum

MaterialApp({ title,theme, home: Scaffold({ appBar, body: Center(child:Chip(
  avatar: CircleAvatar(
    backgroundColor: Colors.grey.shade800,
    child: Text('AB'),
  ),
  label: Text('Aaron Burr'),
)), }), })

parametreler

Chip(
  avatar: CircleAvatar( // avatar alır
    backgroundColor: Colors.grey.shade800,
    child: Text('AB'),
  ),
  label: Text('Aaron Burr'), // text alır
)
  

örnek uygulama

Flutter_Widget_Chip
 
import 'package:flutter/material.dart';
class ChipDemoPage extends StatefulWidget {
  @override
  State createState() => new _ChipDemoPagePageState();
}
class _ChipDemoPagePageState extends State {
  double _volume = 0.0;
  int _value = 1;
  final List _cast = [
    const ActorFilterEntry('Aaron Burr', 'AB'),
    const ActorFilterEntry('Alexander Hamilton', 'AH'),
    const ActorFilterEntry('Eliza Hamilton', 'EH'),
    const ActorFilterEntry('James Madison', 'JM'),
  ];
  List _filters = [];
  Iterable get actorWidgets sync* {
    for (ActorFilterEntry actor in _cast) {
      yield Padding(
        padding: const EdgeInsets.all(4.0),
        child: FilterChip(
          avatar: CircleAvatar(child: Text(actor.initials)),
          label: Text(actor.name),
          selected: _filters.contains(actor.name),
          onSelected: (bool value) {
            setState(() {
              if (value) {
                _filters.add(actor.name);
              } else {
                _filters.removeWhere((String name) {
                  return name == actor.name;
                });
              }
            });
          },
        ),
      );
    }
  }
  @override
  void initState() {
    super.initState();
  }
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          title: new Text('Chip Demo'),
        ),
        body: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                // Chip
                Chip(
                  avatar: CircleAvatar(
                    backgroundColor: Colors.grey.shade800,
                    child: Text('AB'),
                  ),
                  label: Text('Chip'),
                ),
                // InputChip
                InputChip(
                    avatar: CircleAvatar(
                      backgroundColor: Colors.grey.shade800,
                      child: Text('AB'),
                    ),
                    label: Text('InputChip'),
                    onPressed: () {
                      print('I am the one thing in life.');
                    }
                ),
                // ChoiceChip
                Wrap(
                  children: List.generate(3,
                    (int index) {
                      return ChoiceChip(
                        label: Text('Item $index'),
                        selected: _value == index,
                        onSelected: (bool selected) {
                          setState(() {
                            _value = selected ? index : null;
                          });
                        },
                      );
                    },
                  ).toList(),
                ),
                // FilterChip
                Wrap(
                  children: actorWidgets.toList(),
                ),
                Text('Look for: ${_filters.join(', ')}'),
                // ActionChip
                ActionChip(
                  avatar: CircleAvatar(
                    backgroundColor: Colors.grey.shade800,
                    child: Text('AB'),
                    ),
                  label: Text('ActionChip'),
                  onPressed: () {
                    print("If you stand for nothing, Burr, what'll you fall for?");
                  }
                ),
              ],
            )
        )
    );
  }
}
class ActorFilterEntry {
  const ActorFilterEntry(this.name, this.initials);
  final String name;
  final String initials;
}

Bir cevap yazın

KAPAT
%d blogcu bunu beğendi: