Skip to content

Instantly share code, notes, and snippets.

@rurickdev
Last active July 11, 2022 20:58
Show Gist options
  • Save rurickdev/5b473e85267fd8d71a485d967a7ed337 to your computer and use it in GitHub Desktop.
Save rurickdev/5b473e85267fd8d71a485d967a7ed337 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
children: [
// you could use [if] statement inside the list
// if(someting == true)
// otherWidget(),
// use [for] loop inside the list
for(var i=0;i<3;i++) ...[ // use [spread ...] to render more than one widget by iteration
SizedBox(height: 6),
Row(
children: [
for(var j=0; j<3; j++) ...[
SizedBox(width: 6),
MyReusableWidget(i:i,j:j),
],
],
),
]
],
),
),
);
}
}
class MyReusableWidget extends StatelessWidget {
MyReusableWidget({
required this.i,
required this.j,
});
final int i;
final int j;
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
padding: EdgeInsets.all(8.0),
color: Colors.green,
child: Text(
'i:$i j:$j',
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment