jk_bottom_navigation 1.0.0
jk_bottom_navigation: ^1.0.0 copied to clipboard
Native floating bottom tab bar with a draggable glass lens: SwiftUI Liquid Glass on iOS, Jetpack Compose with AGSL refraction on Android.
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:jk_bottom_navigation/jk_bottom_navigation.dart';
import 'package:material_ui/material_ui.dart';
void main() => runApp(const DemoApp());
class DemoApp extends StatelessWidget {
const DemoApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'jk_bottom_navigation',
debugShowCheckedModeBanner: false,
theme: ThemeData(colorSchemeSeed: Colors.blue),
darkTheme: ThemeData(
colorSchemeSeed: Colors.blue,
brightness: Brightness.dark,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _index = 0;
int? _preview;
bool _changePageWhileDragging = true;
bool _showSearch = true;
Color _accent = const Color(0xFF2F80ED);
List<NativeTabItem> _items = const <NativeTabItem>[
NativeTabItem(
title: 'Chats',
iosSymbol: 'bubble.left.and.bubble.right.fill',
androidIcon: 'chat',
badge: 3,
),
NativeTabItem(title: 'Calls', iosSymbol: 'phone.fill', androidIcon: 'call'),
NativeTabItem(
title: 'Contacts',
iosSymbol: 'person.crop.circle.fill',
androidIcon: 'person',
),
NativeTabItem(
title: 'Settings',
iosSymbol: 'gearshape.fill',
androidIcon: 'settings',
),
];
static const List<Color> _accents = <Color>[
Color(0xFF2F80ED),
Color(0xFF34C759),
Color(0xFFFF9500),
Color(0xFFAF52DE),
Color(0xFFFF2D55),
];
void _setBadge(int tab, int? value) {
setState(() {
_items = <NativeTabItem>[
for (int i = 0; i < _items.length; i++)
i == tab
? _items[i].copyWith(badge: value, clearBadge: value == null)
: _items[i],
];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
appBar: AppBar(
title: Text(_items[_preview ?? _index].title),
backgroundColor: Theme.of(context).colorScheme.surface
.withValues(alpha: 0.9),
),
body: IndexedStack(
index: _index,
children: <Widget>[
const _ColorfulList(label: 'Chat', hueOffset: 0),
const _ColorfulList(label: 'Call', hueOffset: 90),
const _ColorfulList(label: 'Contact', hueOffset: 180),
_SettingsPage(
changePageWhileDragging: _changePageWhileDragging,
showSearch: _showSearch,
accent: _accent,
accents: _accents,
badge: _items[0].badge,
onChangePageWhileDragging: (bool v) =>
setState(() => _changePageWhileDragging = v),
onShowSearch: (bool v) => setState(() => _showSearch = v),
onAccent: (Color c) => setState(() => _accent = c),
onBadge: (int? v) => _setBadge(0, v),
),
],
),
bottomNavigationBar: SafeArea(
minimum: const EdgeInsets.fromLTRB(16, 0, 16, 8),
child: NativeTabBar(
items: _items,
currentIndex: _index,
accentColor: _accent,
showSearchButton: _showSearch,
changePageWhileDragging: _changePageWhileDragging,
onTap: (int i) => setState(() {
_index = i;
_preview = null;
}),
onPreview: (int i) => setState(() => _preview = i),
onSearchTap: () =>
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Search tapped'))),
),
),
);
}
}
class _ColorfulList extends StatelessWidget {
const _ColorfulList({required this.label, required this.hueOffset});
final String label;
final double hueOffset;
@override
Widget build(BuildContext context) {
return ListView.builder(
padding: const EdgeInsets.only(bottom: 120),
itemCount: 60,
itemBuilder: (BuildContext context, int i) {
final Color color = HSVColor.fromAHSV(
1,
(hueOffset + i * 14) % 360,
0.55,
0.95,
).toColor();
return Container(
height: 72,
color: color,
alignment: Alignment.centerLeft,
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(
'$label #${i + 1}',
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
);
},
);
}
}
class _SettingsPage extends StatelessWidget {
const _SettingsPage({
required this.changePageWhileDragging,
required this.showSearch,
required this.accent,
required this.accents,
required this.badge,
required this.onChangePageWhileDragging,
required this.onShowSearch,
required this.onAccent,
required this.onBadge,
});
final bool changePageWhileDragging;
final bool showSearch;
final Color accent;
final List<Color> accents;
final int? badge;
final ValueChanged<bool> onChangePageWhileDragging;
final ValueChanged<bool> onShowSearch;
final ValueChanged<Color> onAccent;
final ValueChanged<int?> onBadge;
@override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.only(bottom: 120),
children: <Widget>[
SwitchListTile(
title: const Text('Change page while dragging'),
value: changePageWhileDragging,
onChanged: onChangePageWhileDragging,
),
SwitchListTile(
title: const Text('Show search button'),
value: showSearch,
onChanged: onShowSearch,
),
ListTile(
title: const Text('Chats badge'),
subtitle: Text(badge == null ? 'none' : '$badge'),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
tooltip: 'Remove badge',
icon: const Icon(Icons.remove_circle_outline),
onPressed: badge == null
? null
: () => onBadge(badge! > 1 ? badge! - 1 : null),
),
IconButton(
tooltip: 'Add badge',
icon: const Icon(Icons.add_circle_outline),
onPressed: () => onBadge((badge ?? 0) + 1),
),
],
),
),
const ListTile(title: Text('Accent color')),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Wrap(
spacing: 12,
children: <Widget>[
for (final Color c in accents)
GestureDetector(
onTap: () => onAccent(c),
child: CircleAvatar(
radius: 20,
backgroundColor: c,
child: c == accent
? const Icon(Icons.check, color: Colors.white)
: null,
),
),
],
),
),
const SizedBox(height: 24),
for (int i = 0; i < 20; i++)
ListTile(
leading: CircleAvatar(backgroundColor: accents[i % accents.length]),
title: Text('Filler row ${i + 1}'),
subtitle: Text('Platform: ${defaultTargetPlatform.name}'),
),
],
);
}
}