GopherShy/lib/main.dart

83 lines
2.1 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(
initialUrl: widget.fromIntentLink ?? "gopher://treebrary.org"),
)),
);
}
}
class GopherShy extends StatefulWidget {
const GopherShy({super.key, this.fromIntentLink});
final String? fromIntentLink;
@override
State<GopherShy> createState() => _GopherShyState();
}