nil 1.1.1 nil: ^1.1.1 copied to clipboard
A simple widget to add in the widget tree when you want to show nothing, with minimal impact on performance.
import 'package:flutter/material.dart';
import 'package:nil/nil.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Nil example')),
body: Center(
child: Builder(
builder: (_) {
if (DateTime.now().minute.isEven) {
return const MyWidget();
} else {
return nil;
}
},
),
),
);
}
}
class MyWidget extends StatelessWidget {
const MyWidget({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: 200,
width: 200,
color: Colors.red,
);
}
}