Created
December 26, 2020 16:42
-
-
Save andersonmendesdev/fc0c18110afab9ee7902e460f2ab84f1 to your computer and use it in GitHub Desktop.
Demo listview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyHomePage(), | |
), | |
), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
List<String> listaUsers = []; | |
TextEditingController addColaborador = new TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
final body = ListView( | |
scrollDirection: Axis.vertical, | |
shrinkWrap: true, | |
children: List.generate(listaUsers.length, (index) { | |
Widget child = ListTile( | |
dense: true, | |
title: Row( | |
children: <Widget>[ | |
Text( | |
listaUsers[index], //.id.toString(), | |
style: TextStyle(color: Colors.black, fontSize: 13), | |
), | |
Text(" - "), | |
Text( | |
"", //listaUsers[index].name, | |
style: TextStyle(color: Colors.black, fontSize: 13), | |
), | |
], | |
), | |
onTap: () {}, //=> _onTapped(user), | |
trailing: IconButton( | |
icon: Icon(Icons.remove), | |
onPressed: () { | |
setState(() { | |
listaUsers.removeAt(index); | |
}); | |
}, | |
)); | |
return child; | |
}).toList() | |
..add(Padding( | |
padding: EdgeInsets.only(left: 10), | |
child: Container( | |
padding: EdgeInsets.only(left: 15, right: 15), | |
child: Row(children: <Widget>[ | |
Expanded( | |
child: TextField( | |
controller: addColaborador, | |
decoration: InputDecoration( | |
hintText: "ID COLABORADOR", | |
contentPadding: EdgeInsets.only(bottom: 0), | |
labelStyle: TextStyle(color: Colors.blueAccent)), | |
), | |
), | |
IconButton( | |
icon: Icon(Icons.add), | |
onPressed: () { | |
//_buscarId(); | |
setState(() { | |
listaUsers.add(addColaborador.text); | |
addColaborador.clear(); | |
}); | |
}, | |
) | |
]))))); | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Test'), | |
), | |
body: body, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment