150 lines
4.4 KiB
Dart
150 lines
4.4 KiB
Dart
import 'package:didvan/config/design_config.dart';
|
|
import 'package:didvan/config/theme_data.dart';
|
|
import 'package:didvan/constants/app_icons.dart';
|
|
import 'package:didvan/models/news_details_data.dart';
|
|
import 'package:didvan/models/radar_details_data.dart';
|
|
import 'package:didvan/widgets/didvan/icon_button.dart';
|
|
import 'package:didvan/widgets/didvan/text.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class FloatingNavigationBar extends StatefulWidget {
|
|
final RadarDetailsData? radar;
|
|
final NewsDetailsData? news;
|
|
final ScrollController scrollController;
|
|
final VoidCallback bookmarkCallback;
|
|
const FloatingNavigationBar({
|
|
Key? key,
|
|
this.radar,
|
|
this.news,
|
|
required this.scrollController,
|
|
required this.bookmarkCallback,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<FloatingNavigationBar> createState() => _FloatingNavigationBarState();
|
|
}
|
|
|
|
class _FloatingNavigationBarState extends State<FloatingNavigationBar> {
|
|
bool _isMarked = false;
|
|
|
|
bool get _isRadar => widget.radar != null;
|
|
bool _isScrolled = false;
|
|
|
|
get _item => widget.radar ?? widget.news;
|
|
|
|
@override
|
|
void initState() {
|
|
_isMarked = _item.marked;
|
|
widget.scrollController.addListener(() {
|
|
final position = widget.scrollController.position.pixels;
|
|
if (position > 300 && !_isScrolled) {
|
|
setState(() {
|
|
_isScrolled = true;
|
|
});
|
|
} else if (position < 300 && _isScrolled) {
|
|
setState(() {
|
|
_isScrolled = false;
|
|
});
|
|
}
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Color foregroundColor = DesignConfig.isDark
|
|
? Theme.of(context).colorScheme.focusedBorder
|
|
: Theme.of(context).colorScheme.focused;
|
|
return Container(
|
|
margin: const EdgeInsets.only(left: 32, right: 32, bottom: 20),
|
|
width: double.infinity,
|
|
height: 48,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.navigation,
|
|
borderRadius: BorderRadius.circular(24),
|
|
border: Border.all(
|
|
color: Theme.of(context).colorScheme.cardBorder,
|
|
),
|
|
),
|
|
child: Theme(
|
|
data: Theme.of(context).copyWith(
|
|
iconTheme: IconThemeData(
|
|
color: foregroundColor,
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
IconButton(
|
|
onPressed: () {
|
|
if (_isScrolled) {
|
|
widget.scrollController.animateTo(
|
|
0,
|
|
duration: DesignConfig.lowAnimationDuration,
|
|
curve: Curves.easeIn,
|
|
);
|
|
return;
|
|
}
|
|
Navigator.of(context).pop();
|
|
},
|
|
icon: Icon(
|
|
_isScrolled ? Icons.arrow_upward : Icons.arrow_back,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
if (_isRadar)
|
|
DidvanIconButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
_isMarked = !_isMarked;
|
|
});
|
|
widget.bookmarkCallback();
|
|
},
|
|
icon: _isMarked
|
|
? DidvanIcons.bookmark_solid
|
|
: DidvanIcons.bookmark_regular,
|
|
),
|
|
if (_isRadar)
|
|
IconButton(
|
|
onPressed: () {},
|
|
icon: const Icon(
|
|
DidvanIcons.evaluation_regular,
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 48,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
DidvanText(
|
|
'2',
|
|
color: foregroundColor,
|
|
),
|
|
const SizedBox(width: 4),
|
|
const Icon(
|
|
DidvanIcons.chats_regular,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (!_isRadar)
|
|
IconButton(
|
|
onPressed: () {},
|
|
icon: const Icon(
|
|
DidvanIcons.bookmark_regular,
|
|
),
|
|
),
|
|
if (_isRadar)
|
|
IconButton(
|
|
onPressed: () {},
|
|
icon: const Icon(
|
|
Icons.more_horiz,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|