Assignment List
Loading preview
Starting the Flutter app
A showcase of Flutter's assignment list functionality
import 'package:flutter/material.dart';
const _assignments = [
{'title': 'Widget Exercise', 'due': 'Mar 5', 'status': 'Pending'},
{'title': 'State Lab', 'due': 'Mar 3', 'status': 'Submitted'},
{'title': 'Final Project', 'due': 'Mar 15', 'status': 'Pending'},
];
class AssignmentList extends StatelessWidget {
const AssignmentList({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Assignments')),
body: ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: _assignments.length,
itemBuilder: (context, i) {
final a = _assignments[i];
final isSubmitted = (a['status'] as String) == 'Submitted';
return Card(
margin: const EdgeInsets.only(bottom: 8),
child: ListTile(
leading: CircleAvatar(
backgroundColor: isSubmitted
? Colors.green.withValues(alpha: 0.2)
: Colors.orange.withValues(alpha: 0.2),
child: Icon(
isSubmitted ? Icons.check : Icons.assignment,
color: isSubmitted ? Colors.green : Colors.orange,
),
),
title: Text(a['title'] as String),
subtitle: Text('Due ${a['due']}'),
trailing: Chip(
label: Text(a['status'] as String, style: const TextStyle(fontSize: 12)),
),
onTap: () => _showDemo(context, 'Open ${a['title']} (demo)'),
),
);
},
),
);
}
}
void _showDemo(BuildContext context, String message) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(message)));
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
One derived flag, isSubmitted, does most of the work here: it sets the avatar color and swaps between check and assignment icons, while the Chip prints the raw status. Items come from the const _assignments list via ListView.builder. Due dates are plain strings, so nothing sorts them or flags overdue work, and the sample isn’t in date order. onTap shows a demo SnackBar.
Adapting it
- Store
dueas aDateTime, then sort by it and add an overdue state. - Replace the
statusstring with an enum so a typo can’t silently fall into the pending styling. - Use
onTapto open the assignment’s detail or submission page.