Skip to content

Instantly share code, notes, and snippets.

@dmvvilela
Created October 16, 2024 00:19
Show Gist options
  • Save dmvvilela/b177b0b662717038d600874fd173b182 to your computer and use it in GitHub Desktop.
Save dmvvilela/b177b0b662717038d600874fd173b182 to your computer and use it in GitHub Desktop.
Generated code from pixels2flutter.dev
import 'package:flutter/material.dart';
void main() {
runApp(const HabitTrackerApp());
}
class HabitTrackerApp extends StatelessWidget {
const HabitTrackerApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Habit Tracker',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
),
home: const HabitTrackerPage(),
);
}
}
class HabitTrackerPage extends StatefulWidget {
const HabitTrackerPage({super.key});
@override
_HabitTrackerPageState createState() => _HabitTrackerPageState();
}
class _HabitTrackerPageState extends State<HabitTrackerPage> {
final List<List<bool>> _habitData = List.generate(7, (_) => List.filled(12, false));
final List<String> _days = [
'Segunda',
'Terça',
'Quarta',
'Quinta',
'Sexta',
'Sábado',
'Domingo',
];
final List<String> _weeks = [
'Week 1',
'Week 2',
'Week 3',
'Week 4',
'Week 5',
'Week 6',
'Week 7',
'Week 8',
'Week 9',
'Week 10',
'Week 11',
'Week 12',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Habit Tracker'),
),
body: Column(
children: [
_buildHeader(),
Expanded(
child: _buildTable(),
),
],
),
);
}
Widget _buildHeader() {
return Column(
children: [
Container(
color: Colors.grey[300],
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Text('No Self-Judgment!'),
Text('Feel Proud!'),
Text('Finish Strong!'),
],
),
),
Container(
color: Colors.grey[200],
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Text('You might not see your body change during these weeks...that\'s fine! It is still working!'),
Text('You\'re starting to see results!'),
Text('You\'re seeing results! Don\'t stop there!'),
],
),
),
],
);
}
Widget _buildTable() {
return Table(
border: TableBorder.all(color: Colors.grey),
children: [
TableRow(
children: _weeks.map((week) => _buildWeekCell(week)).toList(),
),
..._days.asMap().entries.map((entry) {
int dayIndex = entry.key;
String day = entry.value;
return TableRow(
children: [
_buildDayCell(day),
..._habitData[dayIndex].asMap().entries.map((entry) {
int weekIndex = entry.key;
return _buildHabitCell(dayIndex, weekIndex);
}).toList(),
],
);
}).toList(),
],
);
}
Widget _buildWeekCell(String week) {
return Container(
color: Colors.grey[300],
padding: const EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text(week),
);
}
Widget _buildDayCell(String day) {
return Container(
color: Colors.grey[300],
padding: const EdgeInsets.all(8.0),
alignment: Alignment.centerLeft,
child: Text(day, style: const TextStyle(fontWeight: FontWeight.bold)),
);
}
Widget _buildHabitCell(int dayIndex, int weekIndex) {
return GestureDetector(
onTap: () {
setState(() {
_habitData[dayIndex][weekIndex] = !_habitData[dayIndex][weekIndex];
});
},
child: Container(
color: _habitData[dayIndex][weekIndex] ? Colors.green[200] : Colors.white,
padding: const EdgeInsets.all(8.0),
alignment: Alignment.center,
child: _habitData[dayIndex][weekIndex] ? const Icon(Icons.check, color: Colors.green) : null,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment