Skip to content

Instantly share code, notes, and snippets.

@giuliano-macedo
Created December 14, 2022 16:45
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 giuliano-macedo/4e0c49968027b5b1c6d0dc70c6e8cbbc to your computer and use it in GitHub Desktop.
Save giuliano-macedo/4e0c49968027b5b1c6d0dc70c6e8cbbc to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Clubbi code challenge',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Clubbi code challenge'),
);
}
}
class ListItem {
final String title;
final String subTitle;
const ListItem(this.title, this.subTitle);
}
class MyHomePage extends StatelessWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: MyList(
items: [
for (var i = 0; i < 10; i++) ListItem("Título $i", "Sub título $i"),
],
),
);
}
}
class MyList extends StatefulWidget {
final List<ListItem> items;
const MyList({Key? key, required this.items}) : super(key: key);
@override
State<MyList> createState() => _MyListState();
}
class _MyListState extends State<MyList> {
late List<ListItem> items = widget.items;
@override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (context, i) => MyListItem(items[i]),
itemCount: items.length,
);
}
}
class MyListItem extends StatelessWidget {
final ListItem item;
const MyListItem(this.item, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
title: Text(item.title),
subtitle: Text(item.subTitle),
leading: FloatingActionButton(
onPressed: (){
// Insira aqui a lógica de:
// Mudar todos os ListItem
// que estão no MyList para o conteúdo do item atual
},
child: const Icon(Icons.refresh),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment