Skip to content

Fix app layout #1095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions app/lib/apps/chatbot/chatbot_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:threebotlogin/apps/chatbot/chatbot_config.dart';
import 'package:threebotlogin/browser.dart';
import 'package:threebotlogin/helpers/logger.dart';
import 'package:threebotlogin/widgets/layout_drawer.dart';


class ChatbotWidget extends StatefulWidget {
final String email;
Expand Down Expand Up @@ -85,15 +85,13 @@ class _ChatbotState extends State<ChatbotWidget>
@override
Widget build(BuildContext context) {
super.build(context);
return LayoutDrawer(
titleText: 'Support',
content: Column(
children: <Widget>[
Expanded(
child: Container(child: iaWebview),
),
],
));
return Column(
children: <Widget>[
Expanded(
child: Container(child: iaWebview),
),
],
);
}

@override
Expand Down
18 changes: 8 additions & 10 deletions app/lib/apps/farmers/farmers_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:threebotlogin/helpers/logger.dart';
import 'package:threebotlogin/models/wallet_data.dart';
import 'package:threebotlogin/screens/scan_screen.dart';
import 'package:threebotlogin/services/shared_preference_service.dart';
import 'package:threebotlogin/widgets/layout_drawer.dart';


bool created = false;

Expand Down Expand Up @@ -153,15 +153,13 @@ class _FarmersState extends State<FarmersWidget>
@override
Widget build(BuildContext context) {
super.build(context);
return LayoutDrawer(
titleText: 'Farming',
content: Column(
children: <Widget>[
Expanded(
child: Container(child: iaWebView),
),
],
));
return Column(
children: <Widget>[
Expanded(
child: Container(child: iaWebView),
),
],
);
}

@override
Expand Down
41 changes: 19 additions & 22 deletions app/lib/apps/news/news_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:http/http.dart' as http;
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:threebotlogin/helpers/globals.dart';
import 'package:threebotlogin/widgets/layout_drawer.dart';

import 'package:xml2json/xml2json.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:timeago/timeago.dart' as timeago;
Expand Down Expand Up @@ -60,27 +60,24 @@ class _NewsScreenState extends State<NewsScreen> {

@override
Widget build(BuildContext context) {
return LayoutDrawer(
titleText: 'News',
content: RefreshIndicator(
onRefresh: () async => _pagingController.refresh(),
child: PagedListView<int, Map<String, dynamic>>(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate<Map<String, dynamic>>(
itemBuilder: (context, entry, index) =>
buildArticleCard(entry, context),
firstPageProgressIndicatorBuilder: (context) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircularProgressIndicator(),
const SizedBox(height: 8),
Text('Loading Articles...',
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold)),
],
),
return RefreshIndicator(
onRefresh: () async => _pagingController.refresh(),
child: PagedListView<int, Map<String, dynamic>>(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate<Map<String, dynamic>>(
itemBuilder: (context, entry, index) =>
buildArticleCard(entry, context),
firstPageProgressIndicatorBuilder: (context) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircularProgressIndicator(),
const SizedBox(height: 8),
Text('Loading Articles...',
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold)),
],
),
),
),
Expand Down
8 changes: 4 additions & 4 deletions app/lib/apps/news/news_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:threebotlogin/clipboard_hack/clipboard_hack.dart';
import 'package:threebotlogin/events/events.dart';
import 'package:threebotlogin/events/go_home_event.dart';
import 'package:threebotlogin/helpers/logger.dart';
import 'package:threebotlogin/widgets/layout_drawer.dart';
import 'package:threebotlogin/widgets/app_layout.dart';
import 'package:url_launcher/url_launcher.dart';

bool created = false;
Expand Down Expand Up @@ -83,9 +83,9 @@ class _NewsState extends State<NewsWidget> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
super.build(context);
return LayoutDrawer(
titleText: 'News',
content: Column(
return AppLayout(
title: 'News',
child: Column(
children: <Widget>[
Expanded(
child: Container(child: iaWebView),
Expand Down
17 changes: 7 additions & 10 deletions app/lib/apps/wallet/wallet_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'package:threebotlogin/models/wallet_data.dart';
import 'package:threebotlogin/screens/scan_screen.dart';
import 'package:threebotlogin/services/crypto_service.dart';
import 'package:threebotlogin/services/shared_preference_service.dart';
import 'package:threebotlogin/widgets/layout_drawer.dart';

bool created = false;

Expand Down Expand Up @@ -184,15 +183,13 @@ class _WalletState extends State<WalletWidget>
@override
Widget build(BuildContext context) {
super.build(context);
return LayoutDrawer(
titleText: 'Wallet',
content: Column(
children: <Widget>[
Expanded(
child: Container(child: iaWebView),
),
],
));
return Column(
children: <Widget>[
Expanded(
child: Container(child: iaWebView),
),
],
);
}

@override
Expand Down
201 changes: 201 additions & 0 deletions app/lib/constants/navigation_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import 'package:flutter/material.dart';
import 'package:threebotlogin/helpers/globals.dart';

/// Data class to hold navigation entry information
class NavigationEntry {
final String name;
final String path;
final IconData icon;
final bool showInBottomNav;
final bool showInDrawer;
final int _cachedIndex;

const NavigationEntry({
required this.name,
required this.path,
required this.icon,
this.showInBottomNav = false,
this.showInDrawer = true,
required int cachedIndex,
}) : _cachedIndex = cachedIndex;

int get index => _cachedIndex;
}

class NavigationConfig {
static final Map<String, NavigationEntry> _pathToEntry = {};
static final Map<String, NavigationEntry> _nameToEntry = {};
static final Map<int, NavigationEntry> _indexToEntry = {};
static List<NavigationEntry>? _bottomNavEntries;
static List<NavigationEntry>? _drawerEntries;
static bool _isInitialized = false;

// Navigation entries configuration
static const List<NavigationEntry> _navigationEntries = [
NavigationEntry(
name: 'Home',
path: '/home',
icon: Icons.home,
showInBottomNav: true,
showInDrawer: true,
cachedIndex: 0,
),
NavigationEntry(
name: 'News',
path: '/news',
icon: Icons.article,
showInDrawer: true,
cachedIndex: 1,
),
NavigationEntry(
name: 'Wallet',
path: '/wallet',
icon: Icons.account_balance_wallet,
showInBottomNav: true,
showInDrawer: true,
cachedIndex: 2,
),
NavigationEntry(
name: 'Farming',
path: '/farming',
icon: Icons.storage,
showInBottomNav: true,
showInDrawer: true,
cachedIndex: 3,
),
NavigationEntry(
name: 'Dao',
path: '/dao',
icon: Icons.how_to_vote_outlined,
showInDrawer: true,
cachedIndex: 4,
),
NavigationEntry(
name: 'Identity',
path: '/identity',
icon: Icons.lock,
showInDrawer: true,
cachedIndex: 5,
),
NavigationEntry(
name: 'Market',
path: '/market',
icon: Icons.show_chart_sharp,
showInDrawer: true,
cachedIndex: 6,
),
NavigationEntry(
name: 'Settings',
path: '/settings',
icon: Icons.settings,
showInBottomNav: true,
showInDrawer: true,
cachedIndex: 7,
),
NavigationEntry(
name: 'Council',
path: '/council',
icon: Icons.how_to_vote_outlined,
showInDrawer: true,
cachedIndex: 8,
),
NavigationEntry(
name: 'Sign',
path: '/sign',
icon: Icons.draw_sharp,
showInDrawer: true,
cachedIndex: 9,
),
NavigationEntry(
name: 'Notifications',
path: '/notifications',
icon: Icons.notifications,
showInDrawer: true,
cachedIndex: 10,
),
];

static void initialize() {
if (_isInitialized) return;

// Build cached maps for O(1) lookups
for (final entry in _navigationEntries) {
_pathToEntry[entry.path] = entry;
_nameToEntry[entry.name] = entry;
_indexToEntry[entry.index] = entry;
}

// Cache filtered lists
_bottomNavEntries = _navigationEntries.where((entry) => entry.showInBottomNav).toList();
_drawerEntries = _navigationEntries.where((entry) => entry.showInDrawer).toList();

_isInitialized = true;
}

static List<NavigationEntry> get navigationEntries {
_ensureInitialized();
return _navigationEntries;
}

static NavigationEntry? getEntryByPath(String path) {
_ensureInitialized();
return _pathToEntry[path];
}

static NavigationEntry? getEntryByName(String name) {
_ensureInitialized();
return _nameToEntry[name];
}

static NavigationEntry? getEntryByIndex(int index) {
_ensureInitialized();
return _indexToEntry[index];
}

static List<NavigationEntry> getBottomNavEntries() {
_ensureInitialized();
return _bottomNavEntries!;
}

static List<NavigationEntry> getDrawerEntries() {
_ensureInitialized();
return _drawerEntries!;
}

static int getBottomNavIndex(int tabIndex) {
_ensureInitialized();
final bottomNavEntries = _bottomNavEntries!;
for (int i = 0; i < bottomNavEntries.length; i++) {
if (bottomNavEntries[i].index == tabIndex) {
return i;
}
}
return 0; // Default to home
}

static int getTabIndexFromBottomNav(int bottomNavIndex) {
_ensureInitialized();
final bottomNavEntries = _bottomNavEntries!;
if (bottomNavIndex >= 0 && bottomNavIndex < bottomNavEntries.length) {
return bottomNavEntries[bottomNavIndex].index;
}
return 0; // Default to home
}

static void navigateToPath(String path) {
final entry = getEntryByPath(path);
if (entry != null) {
Globals().tabController.animateTo(entry.index);
}
}

static void navigateToEntry(NavigationEntry entry) {
Globals().tabController.animateTo(entry.index);
}

static void _ensureInitialized() {
if (!_isInitialized) {
initialize();
}
}
}
Loading