✨ Directory
This commit is contained in:
parent
b5f77c2736
commit
ecb9bffe70
@ -75,7 +75,7 @@ class AuthGuard {
|
|||||||
|
|
||||||
// Use WebView to get authorization url
|
// Use WebView to get authorization url
|
||||||
var responseUrl = await Navigator.of(context).push(MaterialPageRoute(
|
var responseUrl = await Navigator.of(context).push(MaterialPageRoute(
|
||||||
builder: (context) => AuthorizationPage(authorizationUrl),
|
builder: (context) => AuthorizationScreen(authorizationUrl),
|
||||||
));
|
));
|
||||||
|
|
||||||
var responseUri = Uri.parse(responseUrl);
|
var responseUri = Uri.parse(responseUrl);
|
||||||
|
@ -6,7 +6,7 @@ import 'package:firebase_core/firebase_core.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'firebase_options.dart';
|
import 'firebase_options.dart';
|
||||||
|
|
||||||
void initializeFirebase() async {
|
Future<bool> initializeFirebase() async {
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(
|
||||||
options: DefaultFirebaseOptions.currentPlatform,
|
options: DefaultFirebaseOptions.currentPlatform,
|
||||||
);
|
);
|
||||||
@ -28,6 +28,8 @@ void initializeFirebase() async {
|
|||||||
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
|
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> initializeFirebaseMessaging() async {
|
Future<String?> initializeFirebaseMessaging() async {
|
||||||
|
@ -33,7 +33,7 @@ class _AgentNavigationState extends State<AgentNavigation> {
|
|||||||
|
|
||||||
Future<void> initMessage(BuildContext context) async {
|
Future<void> initMessage(BuildContext context) async {
|
||||||
void navigate() {
|
void navigate() {
|
||||||
widget.router.push("/notifications");
|
widget.router.replace("/notifications");
|
||||||
setState(() {
|
setState(() {
|
||||||
_selected = 1;
|
_selected = 1;
|
||||||
});
|
});
|
||||||
@ -64,7 +64,7 @@ class _AgentNavigationState extends State<AgentNavigation> {
|
|||||||
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
|
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
|
||||||
destinations: AgentNavigation.items,
|
destinations: AgentNavigation.items,
|
||||||
onDestinationSelected: (index) {
|
onDestinationSelected: (index) {
|
||||||
widget.router.push(AgentNavigation.destinations[index]);
|
widget.router.replace(AgentNavigation.destinations[index]);
|
||||||
setState(() {
|
setState(() {
|
||||||
_selected = index;
|
_selected = index;
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:goatagent/auth.dart';
|
import 'package:goatagent/auth.dart';
|
||||||
@ -13,7 +12,6 @@ void main() async {
|
|||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
AuthGuard().pickClient();
|
AuthGuard().pickClient();
|
||||||
initializeFirebase();
|
|
||||||
|
|
||||||
runApp(GoatAgent());
|
runApp(GoatAgent());
|
||||||
}
|
}
|
||||||
@ -41,6 +39,15 @@ class GoatAgent extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return FutureBuilder(
|
||||||
|
future: initializeFirebase(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (!snapshot.hasData) {
|
||||||
|
return const Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return MaterialApp.router(
|
return MaterialApp.router(
|
||||||
routerConfig: _router,
|
routerConfig: _router,
|
||||||
title: 'GoatAgent',
|
title: 'GoatAgent',
|
||||||
@ -60,5 +67,7 @@ class GoatAgent extends StatelessWidget {
|
|||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
lib/screens/application.dart
Normal file
23
lib/screens/application.dart
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
|
|
||||||
|
class AuthorizationScreen extends StatelessWidget {
|
||||||
|
final Uri link;
|
||||||
|
|
||||||
|
const AuthorizationScreen(this.link, {super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
body: SafeArea(
|
||||||
|
child: WebViewWidget(
|
||||||
|
controller: WebViewController()
|
||||||
|
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||||
|
..setBackgroundColor(Colors.white)
|
||||||
|
..loadRequest(link)
|
||||||
|
..clearCache(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
|
|
||||||
class AuthorizationPage extends StatelessWidget {
|
class AuthorizationScreen extends StatelessWidget {
|
||||||
final Uri authorizationUrl;
|
final Uri authorizationUrl;
|
||||||
|
|
||||||
const AuthorizationPage(this.authorizationUrl, {super.key});
|
const AuthorizationScreen(this.authorizationUrl, {super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -15,7 +15,7 @@ class AuthorizationPage extends StatelessWidget {
|
|||||||
body: WebViewWidget(
|
body: WebViewWidget(
|
||||||
controller: WebViewController()
|
controller: WebViewController()
|
||||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||||
..setBackgroundColor(Colors.indigo)
|
..setBackgroundColor(Colors.white)
|
||||||
..setNavigationDelegate(NavigationDelegate(
|
..setNavigationDelegate(NavigationDelegate(
|
||||||
onNavigationRequest: (NavigationRequest request) {
|
onNavigationRequest: (NavigationRequest request) {
|
||||||
if (request.url.startsWith('goatagent://auth')) {
|
if (request.url.startsWith('goatagent://auth')) {
|
||||||
@ -25,7 +25,8 @@ class AuthorizationPage extends StatelessWidget {
|
|||||||
return NavigationDecision.navigate;
|
return NavigationDecision.navigate;
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
..loadRequest(authorizationUrl),
|
..loadRequest(authorizationUrl)
|
||||||
|
..clearCache(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,71 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'dart:convert';
|
||||||
|
|
||||||
class DashboardScreen extends StatelessWidget {
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
import 'application.dart';
|
||||||
|
|
||||||
|
class DashboardScreen extends StatefulWidget {
|
||||||
const DashboardScreen({super.key});
|
const DashboardScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DashboardScreen> createState() => _DashboardScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DashboardScreenState extends State<DashboardScreen> {
|
||||||
|
final client = http.Client();
|
||||||
|
final directoryEndpoint =
|
||||||
|
Uri.parse('https://id.smartsheep.studio/.well-known');
|
||||||
|
|
||||||
|
List<dynamic> directory = List.empty();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_pullDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _pullDirectory() async {
|
||||||
|
var response = await client.get(directoryEndpoint);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
setState(() {
|
||||||
|
directory = jsonDecode(utf8.decode(response.bodyBytes))["directory"];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const Scaffold(
|
return Scaffold(
|
||||||
body: Center(
|
body: SafeArea(
|
||||||
child: Text("你好"),
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 20, right: 20, top: 30),
|
||||||
|
child: GridView.count(
|
||||||
|
crossAxisCount: 2,
|
||||||
|
children: directory.map((element) {
|
||||||
|
return Card(
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () async {
|
||||||
|
await Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (context) => AuthorizationScreen(
|
||||||
|
Uri.parse(element["link"]),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
},
|
||||||
|
splashColor: Colors.indigo.withAlpha(30),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
child: ListTile(
|
||||||
|
title: Text(element['name']),
|
||||||
|
subtitle: Text(element['description']),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user