Skip to content

Instantly share code, notes, and snippets.

@romanejaquez
Created March 6, 2022 01:34
Show Gist options
  • Save romanejaquez/c9ae894bab1d024a77f26ddb24a05ca4 to your computer and use it in GitHub Desktop.
Save romanejaquez/c9ae894bab1d024a77f26ddb24a05ca4 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:intl/intl.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(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(20),
child: MyWidget()
),
),
),
);
}
}
class Utils {
static String getFormattedTime(DateTime time) {
var timeFormat = DateFormat("HH:mm");
String timePortion = timeFormat.format(time);
return timePortion;
}
}
class TimeInfo {
DateTime? time;
TimeInfo({ this.time });
}
class MyWidget extends StatelessWidget {
List<TimeInfo> mappedList = [
TimeInfo(time: DateTime.parse('2022-03-05 20:24:00.000')),
TimeInfo(time: DateTime.parse('2022-03-05 21:24:00.000')),
TimeInfo(time: DateTime.parse('2022-03-05 22:24:00.000')),
TimeInfo(time: DateTime.parse('2022-03-05 23:24:00.000')),
];
@override
Widget build(BuildContext context) {
return ListView(
children: [...mappedList.map((m) =>
RichText (
text: TextSpan(
children: [
TextSpan(text: Utils.getFormattedTime(m.time!),
style: const TextStyle(
fontSize: 18 ,
fontWeight: FontWeight.w400,
color: Color(0xff2F2F2F)
)
),
]
)
)
).toList()
]
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment