Skip to content

Instantly share code, notes, and snippets.

@fabiancrx
Created July 25, 2024 14:29
Show Gist options
  • Save fabiancrx/9976e7e8817dd1e8672a5b5ac2e69bbb to your computer and use it in GitHub Desktop.
Save fabiancrx/9976e7e8817dd1e8672a5b5ac2e69bbb to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';
/// Flutter code sample for [BottomNavigationBar].
void main() => runApp(const BottomNavigationBarExampleApp());
class BottomNavigationBarExampleApp extends StatelessWidget {
const BottomNavigationBarExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: BottomNavigationBarExample(),
);
}
}
class BottomNavigationBarExample extends StatefulWidget {
const BottomNavigationBarExample({super.key});
@override
State<BottomNavigationBarExample> createState() =>
_BottomNavigationBarExampleState();
}
class _BottomNavigationBarExampleState
extends State<BottomNavigationBarExample> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const _name = <String>['Device', "Dashboard", "Test"];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
alignment: Alignment.topLeft,
icon: const Icon(Icons.menu_rounded, size: 36),
onPressed: () => {},
),
title: const Text('BottomNavigationBar Sample'),
),
body: ListView.builder(
itemBuilder: (BuildContext context, int index) {
final label = '${_name[_selectedIndex]} Item ${index + 1}';
if (_selectedIndex == 1) {
return Card(child: Center(child: Text(label, style: optionStyle)));
}
return ListTile(
onTap: _selectedIndex == 0
? () {
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => const TabBarExample()));
}
: null,
title: Text(label));
},
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.dashboard),
label: 'Dashboard',
),
BottomNavigationBarItem(
icon: Icon(Icons.science),
label: 'Tests',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
);
}
}
class TabBarExample extends StatelessWidget {
const TabBarExample({super.key});
@override
Widget build(BuildContext context) {
return DefaultTabController(
initialIndex: 1,
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('Device Details'),
bottom: const TabBar(
tabs: <Widget>[
Tab(
icon: Icon(Icons.info),
),
Tab(
icon: Icon(Icons.speed),
),
Tab(
icon: Icon(Icons.settings),
),
],
),
),
body: TabBarView(
children: <Widget>[
Center(
child: Markdown(
data:
"Device Information [like here](https://www.cpsproducts.com/product-details/ts-100/)",
onTapLink: (String text, String? href, String title) {
if (href case final link?) launch(link);
},
),
),
Center(
child: Text(
"Combined view of dashboard readings and below the tests for a specific device"),
),
Center(
child: Text("List of device settings, like designed for the IAQ"),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment