Last active
February 26, 2024 22:30
-
-
Save midsonlajeanty/5dd30305ffa5daed75cd25b063679b5a to your computer and use it in GitHub Desktop.
L4 TP GRID ! - main.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
final String appTtile = 'L4 TP1 - ESIH'; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: appTtile, | |
theme: ThemeData( | |
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | |
useMaterial3: true, | |
), | |
home: MyHomePage(title: appTtile), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({super.key, required this.title}); | |
final String title; | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
final nbBox = 120; | |
final boxPerLigne = 3; | |
final spacing = 10.0; | |
Color _getRandomColor() { | |
Random random = Random(); | |
return Color.fromRGBO( | |
random.nextInt(256), | |
random.nextInt(256), | |
random.nextInt(256), | |
1.0, | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
final removewidth = spacing * (boxPerLigne + 1); | |
final boxWidth = (MediaQuery.of(context).size.width - removewidth) / boxPerLigne; | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Padding( | |
padding: EdgeInsets.all(spacing), | |
child: SingleChildScrollView( | |
child: Wrap( | |
spacing: spacing, | |
runSpacing: spacing, | |
direction: Axis.horizontal, | |
children: <Widget>[ | |
for (var i = 0; i < nbBox; i++) | |
DecoratedBox( | |
decoration: BoxDecoration( | |
color: _getRandomColor() | |
), | |
child: SizedBox.square(dimension: boxWidth,) | |
) | |
], | |
), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () => setState(() {}), | |
tooltip: 'Recharger', | |
child: const Icon(Icons.refresh), | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment