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 createState() => _HomeScreenState(); } class _HomeScreenState extends State { List _stations = []; @override void initState() { super.initState(); _getStations(); } Future _getStations() async { final String stationFile = await rootBundle.loadString("assets/data/stations.json"); final data = await json.decode(stationFile); setState(() { _stations = data["records"]; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Home'), actions: [ 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: _stations.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(text: "เลขขบวน"), TextSpan(text: "\n"), TextSpan( text: _stations[index][1], style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold)), ])), title: Text(_stations[index][2]), subtitle: RichText( text: TextSpan( children: [ TextSpan(text: "Arrival: "), TextSpan(text: _stations[index][8]), TextSpan(text: "\n"), TextSpan(text: "Departure: "), TextSpan(text: _stations[index][9]) ], )), )); }, )), ); } }