Skip to content

Instantly share code, notes, and snippets.

@melwinlobo18
Last active August 12, 2019 06:34
Show Gist options
  • Save melwinlobo18/52edc2c842e75df7aa0a1b2bf9d3a5a1 to your computer and use it in GitHub Desktop.
Save melwinlobo18/52edc2c842e75df7aa0a1b2bf9d3a5a1 to your computer and use it in GitHub Desktop.
Dart code to create TimeTable in a flutter app.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Color kCol1 = Color(0xFF33658A);
Color kCol2 = Color(0xFFA799B7);
Color kCol3 = Color(0xFF979B8D);
Color kCol4 = Color(0xFF8FC0A9);
Color kCol5 = Color(0xFF68B0AB);
Color kCol6 = Color(0xFF8DA9C4);
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Center(
child: Table(
children: <TableRow>[
TableRow(children: <Widget>[
DayTile(
color: kCol1,
text: 'Mon',
),
DayTile(
color: kCol2,
text: 'Tue',
),
DayTile(
color: kCol3,
text: 'Wed',
),
DayTile(
color: kCol4,
text: 'Thur',
),
DayTile(
color: kCol5,
text: 'Fri',
),
DayTile(
color: kCol6,
text: 'Sat',
),
DayTile(
color: Colors.deepOrangeAccent,
text: 'Sun',
),
]),
],
),
),
),
);
}
}
class DayTile extends StatelessWidget {
final Color color;
final String text;
DayTile({this.color = Colors.deepOrangeAccent, this.text = ' '});
@override
Widget build(BuildContext context) {
return FittedBox(
fit: BoxFit.contain,
child: Container(
margin: EdgeInsets.all(2),
color: color,
width: 50.0,
height: 50.0,
child: Center(
child: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment