💄 Optimized UX

This commit is contained in:
2024-02-10 20:08:25 +08:00
parent 30a237741a
commit cb7256af23
6 changed files with 85 additions and 67 deletions

View File

@ -74,9 +74,11 @@ class AuthGuard {
..addAll(authorizationUrl.queryParameters));
// Use WebView to get authorization url
var responseUrl = await Navigator.of(context).push(MaterialPageRoute(
builder: (context) => AuthorizationScreen(authorizationUrl),
));
var responseUrl = await Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (context) => AuthorizationScreen(authorizationUrl),
),
);
var responseUri = Uri.parse(responseUrl);
return await grant

View File

@ -1,11 +1,11 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:goatagent/screens/account.dart';
import 'package:goatagent/screens/dashboard.dart';
import 'package:goatagent/screens/notifications.dart';
class AgentNavigation extends StatefulWidget {
const AgentNavigation({super.key, required this.router});
final GoRouter router;
const AgentNavigation({super.key});
static const items = [
NavigationDestination(
@ -22,20 +22,17 @@ class AgentNavigation extends StatefulWidget {
)
];
static const destinations = ["/", "/notifications", "/account"];
@override
State<AgentNavigation> createState() => _AgentNavigationState();
}
class _AgentNavigationState extends State<AgentNavigation> {
int _selected = 0;
int _view = 0;
Future<void> initMessage(BuildContext context) async {
void navigate() {
widget.router.replace("/notifications");
setState(() {
_selected = 1;
_view = 1;
});
}
@ -59,16 +56,33 @@ class _AgentNavigationState extends State<AgentNavigation> {
@override
Widget build(BuildContext context) {
return NavigationBar(
selectedIndex: _selected,
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
destinations: AgentNavigation.items,
onDestinationSelected: (index) {
widget.router.replace(AgentNavigation.destinations[index]);
setState(() {
_selected = index;
});
},
return Scaffold(
body: Stack(
children: [
Offstage(
offstage: _view != 0,
child: const DashboardScreen(),
),
Offstage(
offstage: _view != 1,
child: const NotificationScreen(),
),
Offstage(
offstage: _view != 2,
child: const AccountScreen(),
)
],
),
bottomNavigationBar: NavigationBar(
selectedIndex: _view,
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
destinations: AgentNavigation.items,
onDestinationSelected: (index) {
setState(() {
_view = index;
});
},
),
);
}
}

View File

@ -20,54 +20,35 @@ void main() async {
await AuthGuard().pickClient();
runApp(GoatAgent());
runApp(const GoatAgent());
}
class GoatAgent extends StatelessWidget {
final _router = GoRouter(
navigatorKey: GlobalKey<NavigatorState>(),
routes: [
GoRoute(
path: '/',
builder: (context, state) => const DashboardScreen(),
),
GoRoute(
path: '/notifications',
builder: (context, state) => const NotificationScreen(),
),
GoRoute(
path: '/account',
builder: (context, state) => const AccountScreen(),
),
GoRoute(
path: '/about',
builder: (context, state) => const AboutScreen(),
),
],
);
GoatAgent({super.key});
const GoatAgent({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _router,
return MaterialApp(
title: 'GoatAgent',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
brightness: Brightness.light,
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.indigo,
accentColor: Colors.indigoAccent,
backgroundColor: Colors.white,
brightness: Brightness.light),
useMaterial3: true,
),
builder: (BuildContext context, Widget? child) {
return Overlay(initialEntries: [
OverlayEntry(
builder: (context) => Scaffold(
body: child,
// bottomNavigationBar: const AgentBottomNavigation()
bottomNavigationBar: AgentNavigation(router: _router),
),
)
]);
},
darkTheme: ThemeData(
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.indigo,
accentColor: Colors.indigoAccent,
backgroundColor: Colors.black12,
brightness: Brightness.dark),
useMaterial3: true,
),
home: const AgentNavigation(),
);
}
}

View File

@ -1,14 +1,22 @@
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class AuthorizationScreen extends StatelessWidget {
class ApplicationScreen extends StatelessWidget {
final Uri link;
final String title;
const AuthorizationScreen(this.link, {super.key});
const ApplicationScreen({super.key, required this.link, required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(32.0),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 18),
child: AppBar(),
)
),
body: SafeArea(
child: WebViewWidget(
controller: WebViewController()

View File

@ -1,10 +1,9 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:goatagent/screens/application.dart';
import 'package:http/http.dart' as http;
import 'application.dart';
class DashboardScreen extends StatefulWidget {
const DashboardScreen({super.key});
@ -46,9 +45,11 @@ class _DashboardScreenState extends State<DashboardScreen> {
return Card(
child: InkWell(
onTap: () async {
await Navigator.of(context).push(MaterialPageRoute(
builder: (context) => AuthorizationScreen(
Uri.parse(element["link"]),
var link = element["link"];
Navigator.of(context, rootNavigator: true).push(MaterialPageRoute(
builder: (context) => ApplicationScreen(
link: Uri.parse(link),
title: element["name"],
),
));
},