Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(MaterialApp(
- home: Scaffold(
- appBar: AppBar(
- title: Text('demo App'),
- centerTitle: true,
- ),
- body: mainApp(),
- ),
- ));
- class mainApp extends StatefulWidget {
- @override
- _mainAppState createState() => _mainAppState();
- }
- class _mainAppState extends State<mainApp> {
- var txt = TextEditingController();
- final List<String> names = <String>['Paweł','Ania','Michał','Władek'];
- int size = 4;
- @override
- Widget build(BuildContext context) {
- return Center(
- child: Container(
- child: Column(
- children: <Widget>[
- Container(
- color: Colors.teal,
- padding: EdgeInsets.all(30),
- margin: EdgeInsets.only(
- bottom: 20,
- ),
- child: TextField(
- controller: txt,
- onSubmitted: (String str)
- {
- setState(() {
- names.insert(0, str);
- size++;
- txt.text = "";
- });
- },
- decoration: InputDecoration(
- hintText: 'Insert text here!'
- ),
- ),
- ),
- Expanded(
- child: ListView.builder(
- itemCount: size,
- itemBuilder: (_context, index)
- {
- return Container(
- margin: EdgeInsets.all(10),
- padding: EdgeInsets.all(12),
- decoration: BoxDecoration(
- color: Colors.teal,
- borderRadius: BorderRadius.only(
- topRight: Radius.circular(10),
- topLeft: Radius.circular(10),
- bottomRight: Radius.circular(10),
- bottomLeft: Radius.circular(10),
- )
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Container(
- child: Text('Id: $index Name: ${names[index]}'),
- ),
- GestureDetector(
- onTap: ()
- {
- //remove
- setState(() {
- names.removeAt(index);
- size--;
- });
- },
- child: Container(
- child: Icon(Icons.remove),
- color: Colors.greenAccent,
- ),
- )
- ],
- ),
- );
- }
- ),
- )
- ],
- ),
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement