mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
87 lines
2.3 KiB
Dart
87 lines
2.3 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flutter code sample InputChip.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() => runApp(const ChipApp());
|
|
|
|
class ChipApp extends StatelessWidget {
|
|
const ChipApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
|
|
home: const InputChipExample(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class InputChipExample extends StatefulWidget {
|
|
const InputChipExample({super.key});
|
|
|
|
@override
|
|
State<InputChipExample> createState() => _InputChipExampleState();
|
|
}
|
|
|
|
class _InputChipExampleState extends State<InputChipExample> {
|
|
int inputs = 3;
|
|
int? selectedIndex;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('InputChip Sample'),
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Wrap(
|
|
alignment: WrapAlignment.center,
|
|
spacing: 5.0,
|
|
children: List<Widget>.generate(
|
|
inputs,
|
|
(int index) {
|
|
return InputChip(
|
|
label: Text('Person ${index + 1}'),
|
|
selected: selectedIndex == index,
|
|
onSelected: (bool selected) {
|
|
setState(() {
|
|
if (selectedIndex == index) {
|
|
selectedIndex = null;
|
|
} else {
|
|
selectedIndex = index;
|
|
}
|
|
});
|
|
},
|
|
onDeleted: () {
|
|
setState(() {
|
|
inputs = inputs - 1;
|
|
});
|
|
},
|
|
);
|
|
},
|
|
).toList(),
|
|
),
|
|
const SizedBox(height: 10),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
inputs = 3;
|
|
});
|
|
},
|
|
child: const Text('Reset'),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|