I have a problem. I want to create a own button class with Icon and text. Unfortunately I got on my screen Null check operator used on a null value
and Bottom Overflowed by 99516 Pixels
.
How can I solve this kind of issues?
I tried with an if condition, as you can see here
? Text(label!.name)
: Container(), // Text unter dem Icon
But nothing worked
Button class
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../utils/definitions.dart';
import 'icons.dart';
import '../model/label.dart';
class LabelButton extends StatelessWidget {
final Label? label;
final VoidStringCallback? process;
LabelButton({required this.label, required this.process, Key? key})
: super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
process!(label!.name);
HapticFeedback.lightImpact();
},
child: Container(
width: 100, // Breite anpassen
height: 100, // Höhe anpassen
decoration: BoxDecoration(
color: Colors.grey, // Hintergrundfarbe anpassen
border: Border.all(
color: Colors.black, // Rahmenfarbe anpassen
width: 2, // Rahmendicke anpassen
),
borderRadius: BorderRadius.circular(12), // Eckradius anpassen
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(iconList
.firstWhere((element) => element.name == label!.uiIcon)
.icon),
(label != Null)
? Text(label!.name)
: Container(), // Text unter dem Icon
],
),
),
);
}
const LabelButton._(this.label, this.process, {Key? key}) : super(key: key);
static LabelButton createBlank() {
return const LabelButton._(null, null);
}
}
How I am calling this inside my Main
@override
Widget build(BuildContext context) {
var widgetList = labels.map((Label l) {
return LabelButton(label: l, process: processClick);
}).toList();
const int buttonCountPerRow = 5;
var chunks = [];
for (var i = 0; i < widgetList.length; i += buttonCountPerRow) {
var end = (i + buttonCountPerRow < widgetList.length)
? i + buttonCountPerRow
: widgetList.length;
chunks.add(widgetList.sublist(i, end));
}
if (chunks.isNotEmpty) {
var remainder = buttonCountPerRow - chunks.last.length;
for (var i = 0; i != remainder; ++i) {
chunks.last.add(LabelButton.createBlank());
}
}