shtuff
This commit is contained in:
@@ -12,6 +12,7 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class InitialStartup extends StatefulWidget {
|
||||
|
||||
@@ -324,6 +325,8 @@ class _page3 extends InitialStartupPage {
|
||||
|
||||
class _page3State extends State<_page3> {
|
||||
|
||||
bool _loadingAudio = false;
|
||||
|
||||
Future<bool> _announcementsUploaded() async {
|
||||
try {
|
||||
Uint8List bytes = await LiveInformation().announcementModule.getBundleBytes();
|
||||
@@ -393,6 +396,7 @@ class _page3State extends State<_page3> {
|
||||
height: 4,
|
||||
),
|
||||
|
||||
if (!_loadingAudio)
|
||||
FutureBuilder(
|
||||
future: _announcementsUploaded(),
|
||||
builder: (context, val) {
|
||||
@@ -412,6 +416,10 @@ class _page3State extends State<_page3> {
|
||||
text: Text(text),
|
||||
onPressed: () async {
|
||||
|
||||
setState(() {
|
||||
_loadingAudio = true;
|
||||
});
|
||||
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: [
|
||||
@@ -419,6 +427,8 @@ class _page3State extends State<_page3> {
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
|
||||
if (result != null) {
|
||||
late Uint8List bytes;
|
||||
|
||||
@@ -434,13 +444,25 @@ class _page3State extends State<_page3> {
|
||||
|
||||
AnnouncementCache cache = LiveInformation().announcementModule.announcementCache;
|
||||
|
||||
if (!kIsWeb) {
|
||||
|
||||
// Use shared preferences to store the file location
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
prefs.setString("AnnouncementsFileLocation", result.files.single.path!);
|
||||
}
|
||||
|
||||
// load a random announcement to ensure that the file is usable
|
||||
await cache.loadAnnouncementsFromBytes(bytes, ["S_WALTHAMSTOW_CENTRAL_001.mp3"]);
|
||||
|
||||
setState(() {
|
||||
|
||||
_loadingAudio = false;
|
||||
});
|
||||
|
||||
} else {
|
||||
setState(() {
|
||||
_loadingAudio = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -450,11 +472,62 @@ class _page3State extends State<_page3> {
|
||||
);
|
||||
},
|
||||
)
|
||||
else
|
||||
CircularProgressIndicator(),
|
||||
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
|
||||
FutureBuilder(
|
||||
future: _announcementsUploaded(),
|
||||
builder: (context, val) {
|
||||
bool isEnabled = true;
|
||||
String text = "Continue";
|
||||
Color color = Colors.white;
|
||||
|
||||
if (val.hasData) {
|
||||
isEnabled = val.data!;
|
||||
}
|
||||
if (!isEnabled) {
|
||||
text = "Complete the prerequisites to continue";
|
||||
}
|
||||
|
||||
return ShadButton(
|
||||
text: Text(text),
|
||||
onPressed: () async {
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: Text("You're all setup"),
|
||||
description: Text("You can now continue to the application. \nTry not to annoy anyone on the bus! ;)"),
|
||||
actions: [
|
||||
ShadButton(
|
||||
text: Text("Continue to application"),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, "/");
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
barrierDismissible: false
|
||||
);
|
||||
|
||||
},
|
||||
enabled: isEnabled,
|
||||
backgroundColor: color,
|
||||
width: double.infinity,
|
||||
);
|
||||
},
|
||||
)
|
||||
|
||||
],
|
||||
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user