/************************************ * flutter template using bottom nav ************************************/ import 'package:flutter/material.dart'; import 'package:flutter_syntax_view/flutter_syntax_view.dart'; import 'dart:convert'; import './codes.dart'; // // labels for nav destination and body // List labels = ['Home', 'Demo', 'Help', 'Source']; // // nav destinations widget for bottom nav // List nav_destinations = [ NavigationDestination(icon: Icon (Icons.home), label: labels[0]), NavigationDestination(icon: Icon (Icons.bluetooth), label: labels[1]), NavigationDestination(icon: Icon (Icons.help), label: labels[2]), NavigationDestination(icon: Icon (Icons.source), label: labels[3])]; // // class showing passing parameters // class Body extends StatelessWidget { Body(this.text); final String text; @override Widget build(BuildContext bc){ return (Center(child:Text(text)));}} // // function example // Widget showSource(BuildContext context){ num line = LineSplitter().convert(code).length; return SizedBox(height:16.0 * line, child:Padding( padding:EdgeInsets.fromLTRB(0,0,20,0), child:SyntaxView( code: code, syntax: Syntax.DART, syntaxTheme: SyntaxTheme.vscodeDark(), withZoom:true, withLinesCount:true, expanded:true)));} // // class statelesswidget // class Source extends StatelessWidget{ @override Widget build(BuildContext context) { return Scaffold(appBar:AppBar(title: Text('Source Code')), body: SingleChildScrollView(child:showSource(context)));}} // // class example, that changes icon back button // class Help extends StatelessWidget{ @override Widget build(BuildContext context){ return Scaffold(appBar:AppBar( leading:IconButton(icon:Icon(Icons.close, color:Colors.black), onPressed:() => Navigator.push(context, MaterialPageRoute(builder:(context)=>MyApp()))), title: Text('Help')), body: Center(child:Text('Help')));}} // // main // void main() {runApp(const MyApp());} // // class example statefulwidget // class MyApp extends StatefulWidget { const MyApp({super.key}); @override State createState() => _MyAppState();} class _MyAppState extends State { int selectedPageIndex = 0; @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Demo', home: Scaffold( body: [ Body(labels[0]), // change this to your own container Body(labels[1]), // maybe refactor on a separate file Help(), // example change back button in appbar Source() // show source file example widget ][selectedPageIndex], bottomNavigationBar: NavigationBar( selectedIndex: selectedPageIndex, onDestinationSelected: (int index) { setState((){selectedPageIndex = index;});}, destinations: nav_destinations)));}}