Skip to content

Commit

Permalink
Merge branch 'search'
Browse files Browse the repository at this point in the history
  • Loading branch information
namanshergill committed Apr 21, 2021
2 parents e5682a2 + 15557c4 commit 01591a1
Show file tree
Hide file tree
Showing 60 changed files with 2,335 additions and 3,296 deletions.
2 changes: 1 addition & 1 deletion lib/app/Dio/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CacheManager {
CustomCacheOptions(refresh);

static CustomCacheOptions search({bool refresh = false}) =>
CustomCacheOptions(refresh);
CustomCacheOptions(refresh, cachePolicy: CachePolicy.refreshForceCache);

static CustomCacheOptions events({bool refresh = false}) =>
CustomCacheOptions(refresh);
Expand Down
2 changes: 1 addition & 1 deletion lib/app/Dio/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class GetDio {
if (applyBaseURL) options.baseUrl = baseURL;
options.headers["Accept"] = acceptHeader ?? "application/json";
options.headers["setContentType"] = "application/json";
options.headers['User-Agent'] = "com.felix.onehub";
if (loggedIn == false) {
if (loginRequired) throw Exception('Not authenticated.');
} else {
Expand All @@ -55,7 +56,6 @@ class GetDio {
debugPrint(error.toString());
}
}

// Check cache first and return cached data if supplied maxAge
// has not elapsed.
if (cacheEnabled) {
Expand Down
6 changes: 3 additions & 3 deletions lib/app/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class Global {
static final Logger log = Logger();
static String? _directoryPath;
static String? get directoryPath => _directoryPath;
static DbCacheStore? _cacheStore;
static DbCacheStore get cacheStore => _cacheStore!;
static HiveCacheStore? _cacheStore;
static HiveCacheStore get cacheStore => _cacheStore!;

static Future setupAppCache() async {
await getApplicationDocumentsDirectory()
.then((value) => _directoryPath = value.path);
_cacheStore = DbCacheStore(databasePath: _directoryPath!);
_cacheStore = HiveCacheStore(_directoryPath);
}
}
1 change: 0 additions & 1 deletion lib/common/animations/size_expanded_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class _SizeExpandedSectionState extends State<SizeExpandedSection>
prepareAnimations();
}

//Setting up the animation
void prepareAnimations() {
expandController = AnimationController(
vsync: this,
Expand Down
4 changes: 2 additions & 2 deletions lib/common/api_wrapper_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class APIWrapperController {
void Function()? refresh;
}

typedef ResponseBuilder<T>(BuildContext context, T data);
typedef ErrorBuilder(BuildContext context, String? error);
typedef ResponseBuilder<T> = Widget Function(BuildContext context, T data);
typedef ErrorBuilder = Widget Function(BuildContext context, String? error);

class APIWrapper<T> extends StatefulWidget {
final Future<T>? getCall;
Expand Down
129 changes: 73 additions & 56 deletions lib/common/app_scroll_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,63 @@ import 'package:onehub/style/colors.dart';
import 'app_tab_bar.dart';

class AppScrollView extends StatelessWidget {
final ScrollViewAppBar? scrollViewAppBar;
final Widget? scrollViewAppBar;
final List<Widget>? tabViews;
final Widget? child;
final bool loading;
final TabController? tabController;
final Color childrenColor;
final ScrollController scrollController;
AppScrollView(
{this.scrollViewAppBar,
this.tabController,
this.tabViews,
required this.scrollController,
this.child,
this.childrenColor = AppColor.onBackground,
this.loading = false});
@override
Widget build(BuildContext context) {
return NestedScrollView(headerSliverBuilder: (context, value) {
return [
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverSafeArea(
sliver: scrollViewAppBar!,
),
)
];
}, body: Builder(builder: (context) {
NestedScrollView.sliverOverlapAbsorberHandleFor(context);

return AnimatedSwitcher(
duration: Duration(milliseconds: 50),
child: loading
? Container(
color: childrenColor,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 48.0),
child: LoadingIndicator(),
),
],
))
: Container(
color: childrenColor,
child: TabBarView(
controller: tabController,
children: List.generate(
tabViews!.length, (index) => tabViews![index]),
),
return NestedScrollView(
controller: scrollController,
headerSliverBuilder: (context, value) {
return [
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverSafeArea(
sliver: scrollViewAppBar!,
),
);
}));
)
];
},
body: Builder(builder: (context) {
NestedScrollView.sliverOverlapAbsorberHandleFor(context);

return AnimatedSwitcher(
duration: Duration(milliseconds: 50),
child: loading
? Container(
color: childrenColor,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 48.0),
child: LoadingIndicator(),
),
],
))
: child != null
? child
: Container(
color: childrenColor,
child: TabBarView(
controller: tabController,
children: List.generate(
tabViews!.length, (index) => tabViews![index]),
),
),
);
}));
}
}

Expand All @@ -66,12 +75,16 @@ class ScrollViewAppBar extends StatelessWidget {
final double? bottomPadding;
final TabController? tabController;
final Widget? bottomHeader;
final Color? backgroundColor;
final EdgeInsets? padding;
ScrollViewAppBar(
{this.tabs,
this.appBarWidget,
this.bottomHeader,
this.backgroundColor,
this.tabController,
this.bottomPadding,
this.padding,
this.flexibleBackgroundWidget,
this.collapsedHeight,
this.expandedHeight});
Expand All @@ -86,36 +99,40 @@ class ScrollViewAppBar extends StatelessWidget {
},
)
: null,
backgroundColor: backgroundColor,
title: SliverAppBarTitle(child: appBarWidget),
pinned: true,
expandedHeight: expandedHeight,
collapsedHeight: collapsedHeight,
flexibleSpace: FlexibleSpaceBar(
background: Padding(
padding:
const EdgeInsets.only(top: 16, right: 24, left: 24, bottom: 60),
padding: padding ??
EdgeInsets.only(
top: 16, right: 24, left: 24, bottom: tabs != null ? 60 : 0),
child: flexibleBackgroundWidget,
),
),
bottom: PreferredSize(
preferredSize: Size.fromHeight(bottomPadding ?? 0),
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: bottomHeader ?? Container(),
),
AppTabBar(
controller: tabController,
tabs: List.generate(
tabs!.length,
(index) => AppTab(
title: tabs![index],
)),
),
],
),
),
bottom: tabs != null
? PreferredSize(
preferredSize: Size.fromHeight(bottomPadding ?? 0),
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: bottomHeader ?? Container(),
),
AppTabBar(
controller: tabController,
tabs: List.generate(
tabs!.length,
(index) => AppTab(
title: tabs![index],
)),
),
],
),
)
: null,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/common/auth_popup/widgets/codeInfoBox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class _CodeInfoBoxState extends State<CodeInfoBox> {
),
),
onTap: () {
showURLBottomActionsMenu(
linkHandler(
context, widget.deviceCodeModel.verificationUri,
shareDescription:
'Enter the code ${widget.deviceCodeModel.userCode} on:');
Expand Down
10 changes: 9 additions & 1 deletion lib/common/bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ void showBottomActionsMenu(BuildContext context,
));
}

void linkHandler(BuildContext context, String? url,
{String? shareDescription}) async {
bool canLaunchLink = await canLaunch(url!);
if (canLaunchLink)
showURLBottomActionsMenu(context, url, shareDescription: shareDescription);
}

void showURLBottomActionsMenu(BuildContext context, String? url,
{String? shareDescription}) {
showBottomActionsMenu(context, headerText: url, childWidget: (context) {
Expand Down Expand Up @@ -113,7 +120,8 @@ void showURLBottomActionsMenu(BuildContext context, String? url,
});
}

typedef ScrollChild(BuildContext context, ScrollController scrollController);
typedef ScrollChild = Widget Function(
BuildContext context, ScrollController scrollController);

void showScrollableBottomActionsMenu(BuildContext context,
{required ScrollChild child, String? titleText, Widget? titleWidget}) {
Expand Down
18 changes: 18 additions & 0 deletions lib/common/code_block_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter_highlight/flutter_highlight.dart';
import 'package:flutter_highlight/themes/monokai-sublime.dart';

class CodeBlockView extends StatelessWidget {
final String data;
final String? language;
CodeBlockView(this.data, {this.language});
@override
Widget build(BuildContext context) {
return HighlightView(
data,
backgroundColor: Colors.transparent,
theme: monokaiSublimeTheme,
language: language ?? 'txt',
);
}
}
9 changes: 8 additions & 1 deletion lib/common/events/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ import 'package:provider/provider.dart';
class Events extends StatelessWidget {
final bool privateEvents;
final String? specificUser;
Events({this.privateEvents = true, this.specificUser});
final ScrollController scrollController;

Events(
{this.privateEvents = true,
this.specificUser,
required this.scrollController});
@override
Widget build(BuildContext context) {
final _user = Provider.of<CurrentUserProvider>(context);
return InfiniteScrollWrapper<EventsModel>(
firstDivider: false,
topSpacing: 24,
spacing: 32,
scrollController: scrollController,
isNestedScrollViewChild: true,
future: (pageNumber, pageSize, refresh, _) {
if (specificUser != null)
return EventsService.getUserEvents(specificUser,
Expand Down
Loading

0 comments on commit 01591a1

Please sign in to comment.