srt_app/lib/pages/home.dart

88 lines
2.8 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
List _schedule = [];
@override
void initState() {
super.initState();
_getSchedule();
}
Future<void> _getSchedule() async {
final String scheduleFile =
await rootBundle.loadString("assets/data/schedule.json");
final data = await json.decode(scheduleFile);
setState(() {
_schedule = data["records"];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Home'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('More')));
},
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: () => {print("deez")}, child: const Icon(Icons.add)),
body: Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: ListView.builder(
itemCount: _schedule.length,
itemBuilder: (context, index) {
return Card(
elevation: 4.0,
margin: const EdgeInsets.symmetric(vertical: 5.0),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 25.0),
leading: RichText(
textAlign: TextAlign.center,
text: TextSpan(children: <TextSpan>[
TextSpan(text: "เลขขบวน"),
TextSpan(text: "\n"),
TextSpan(
text: _schedule[index][1],
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold)),
])),
title: Text(_schedule[index][2]),
subtitle: RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: "Arrival: "),
TextSpan(text: _schedule[index][8]),
TextSpan(text: "\n"),
TextSpan(text: "Departure: "),
TextSpan(text: _schedule[index][9])
],
)),
));
},
)),
);
}
}