Skip to content

Instantly share code, notes, and snippets.

View daiki1003's full-sized avatar
🏠
Working from home

ashdik daiki1003

🏠
Working from home
View GitHub Profile
class BadAssociationWidget extends StatelessWidget {
const BadAssociationWidget();
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16),
child: Text('Hello with Margin'),
);
}
class AwesomeWidget extends StatelessWidget {
const AwesomeWidget({
super.key,
});
@override
Widget build(BuildContext, context) {
void showUserScreen() {
// show user screen
}
class Awesome {
const Awesome.positional(this.value);
const Awesome.named({required this.value});
final int value;
}
/// Instanciation
final positional = Awesome.positional(1);
class SomeWidget extends ConsumerWidget {
const SomeWidget({
super.key,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final musicId = ref.watch(musicIdProvider);
final volume = ref.watch(volumeProvider);
class SomeWidget extends ConsumerWidget {
const SomeWidget({
super.key,
});
Future<void> _playMusic({
required BuildContext context,
required WidgetRef ref,
required int musicId,
required int volume,
class MyGreatestWidget extends StatelessWidget {
const MyGreatestWidget({
Key? key,
required this.onPressed,
}) : super(key: key);
final ValueCallback<String> onPressed;
@override
Widget build(BuildContext context) {
class SomeBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Builder(
builder: (innerContext) {
return NewIconButton();
},
);
}
}
class SomeBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Builder(
builder: (innerContext) {
return IconButton(
onPressed: () {
final theme = Theme.of(context);
...,
}
class SomeBigWidgetState extends State<SomeBigWidget> {
@override
Widget build(BuildContext context) {
return Stack(
children: [
_buildSomeWidget1(),
_buildSomeWidget2(),
_buildSomeWidget3(),
_buildLikeButton(),
],
// some_screen.dart
class SomeScreen extends StatelessWidget {
static GoRoute route({
List<GoRoute> routes = const <GoRoute>[],
}) {
return GoRoute(
path: routeName,
name: routeName,
builder: (_, __) => const SomeScreen(),
routes: routes,