Skip to content

Instantly share code, notes, and snippets.

@andersonmendesdev
Created December 26, 2020 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonmendesdev/fc0c18110afab9ee7902e460f2ab84f1 to your computer and use it in GitHub Desktop.
Save andersonmendesdev/fc0c18110afab9ee7902e460f2ab84f1 to your computer and use it in GitHub Desktop.
Demo listview
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