GopherShy/lib/main.dart
Felisp 98b8e2b3bf Update Features, add todos, remove wrong comments
Maybe next Time I should reread the spec, instead
of relying on memory from half a year ago
2024-11-08 00:19:31 +01:00

83 lines
2.2 KiB
Dart

// Warnings ignored for development, we can spit 'const' everywhere
// once it will matter
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:app_links/app_links.dart';
import 'package:gophershy/gopher_browser.dart';
void main() {
runApp(const GopherShy());
}
class _GopherShyState extends State<GopherShy> {
late final AppLinks _appLinks;
final _navigatorKey = GlobalKey<NavigatorState>();
StreamSubscription<Uri>? _linkSubscription;
@override
void initState() {
super.initState();
_appLinks = AppLinks();
_initDeepLinks();
print("Launching bcs: ${widget.fromIntentLink}");
}
@override
void dispose() {
_linkSubscription?.cancel();
super.dispose();
}
Future<void> _initDeepLinks() async {
// Handle links
_linkSubscription = _appLinks.uriLinkStream.listen((uri) {
debugPrint('GopherShy: onAppLink: $uri');
_openAppLink(uri);
});
}
void _openAppLink(Uri uri) {
_navigatorKey.currentState?.push(MaterialPageRoute<void>(
builder: (BuildContext context) {
return GopherShy(fromIntentLink: uri.toString());
},
));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: _navigatorKey,
title: 'GopherShy',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: SafeArea(
child: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(50),
child: Text(
"${widget.fromIntentLink} Whoaaaaa",
style: TextStyle(fontSize: 50),
),
),
// In future replace with bookmark view
body: GopherBrowser( //TODO: replace default url with homepage from prefs
initialUrl: widget.fromIntentLink ?? "gopher://treebrary.org"),
)),
);
}
}
class GopherShy extends StatefulWidget {
const GopherShy({super.key, this.fromIntentLink});
final String? fromIntentLink;
@override
State<GopherShy> createState() => _GopherShyState();
}