Skip to content

Commit

Permalink
Minor UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
srgtuszy committed Oct 22, 2024
1 parent 2005a26 commit 5b28456
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 75 deletions.
10 changes: 4 additions & 6 deletions lib/electricity_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ class _ElectricityChartState extends State<ElectricityChart> {
final formattedDate =
'${date.hour}:${date.minute}:${date.second}';
return LineTooltipItem(
'Time: $formattedDate\nUsage: ${spot.y.toStringAsFixed(2)} kWh',
'Time: $formattedDate\nUsage: ${spot.y.toStringAsFixed(2)} kWh',
const TextStyle(color: Colors.white),
);
}).toList();
},
),
),
gridData: const FlGridData(show: true, drawVerticalLine: false),
gridData: const FlGridData(show: true, drawVerticalLine: true),
lineBarsData: [
LineChartBarData(
spots: _spots,
Expand Down Expand Up @@ -92,8 +92,7 @@ class _ElectricityChartState extends State<ElectricityChart> {
reservedSize: 50,
getTitlesWidget: (value, meta) {
return Text('${value.toInt()}',
style:
const TextStyle(color: Colors.black54, fontSize: 12));
style: Theme.of(context).textTheme.labelSmall);
},
),
),
Expand All @@ -110,8 +109,7 @@ class _ElectricityChartState extends State<ElectricityChart> {
return SideTitleWidget(
axisSide: meta.axisSide,
child: Text(formattedTime,
style:
const TextStyle(color: Colors.black54, fontSize: 10)),
style: Theme.of(context).textTheme.labelSmall),
);
},
),
Expand Down
142 changes: 73 additions & 69 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,77 +193,81 @@ class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
height: 300,
child: ElectricityChart(),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _toggleDataGeneration,
child: Text(isGenerating
? 'Stop Generating Data'
: 'Start Generating Data'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _clearFirestoreData,
child: const Text('Clear Firestore Data'),
),
const SizedBox(height: 10),
const SizedBox(height: 10),
StatefulBuilder(
builder: (context, setState) {
return _isLoading
? const CircularProgressIndicator()
: ElevatedButton(
onPressed: _triggerGenerateTips,
child: const Text('Generate Tips'),
);
},
),
const SizedBox(height: 20),
StreamBuilder<List<Tip>>(
stream: _tipStore.streamTips(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final tips = snapshot.data!;
return GridView.builder(
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
),
itemCount: tips.length,
itemBuilder: (context, index) {
final tip = tips[index];
return Card(
child: Padding(
padding: const EdgeInsets.all(10),
child: Center(
child: Text(
tip.tip,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 14),
maxLines: 6,
overflow: TextOverflow.fade,
child: Padding(
padding: const EdgeInsets.all(30),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
height: 300,
child: ElectricityChart(),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _toggleDataGeneration,
child: Text(isGenerating
? 'Stop Generating Data'
: 'Start Generating Data'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _clearFirestoreData,
child: const Text('Clear Firestore Data'),
),
const SizedBox(height: 10),
const SizedBox(height: 10),
StatefulBuilder(
builder: (context, setState) {
return _isLoading
? const CircularProgressIndicator()
: ElevatedButton(
onPressed: _triggerGenerateTips,
child: const Text('Generate Tips'),
);
},
),
const SizedBox(height: 20),
StreamBuilder<List<Tip>>(
stream: _tipStore.streamTips(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final tips = snapshot.data!;
return GridView.builder(
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
),
itemCount: tips.length,
itemBuilder: (context, index) {
final tip = tips[index];
return Card(
child: Padding(
padding: const EdgeInsets.all(10),
child: Center(
child: Text(
tip.tip,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 14),
maxLines: 6,
overflow: TextOverflow.fade,
),
),
),
),
);
},
);
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
],
);
},
);
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
],
),
),
);
}
Expand Down

0 comments on commit 5b28456

Please sign in to comment.