current position:Home>Fleet series 9: Custom bottomnavigationbar
Fleet series 9: Custom bottomnavigationbar
2022-05-15 07:48:25【Xiang Yu Han】
Source code address :GitHub - hhbbeijing/flutter_app_test Submission date :2022-5-10
In the last chapter, we have been able to customize the picture library , In this example, we will combine ttf Customize bottomNavigationBar, As an enterprise app Part of .
One 、 Make TTF
1.1 take png Convert to SVG:
PNG turn SVG – Online will PNG Convert document to SVG
After successful conversion, you can preview the picture , Otherwise, the display fails .
2.2 Make TTF
website :iconfont- Alibaba vector icon library
After logging in , Upload SVG Go to your own project
download
Two 、 Customize BottomNavigationBar
2.1 Custom layout
import 'package:flutter/material.dart';
import 'package:flutter_app_test/pages/example/ttf/MyIcons.dart';
void main() {
runApp(Main());
}
class Main extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.green,
),
home: MainPage());
}
}
class MainPage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<MainPage> {
late int currentIndex;
@override
void initState() {
super.initState();
currentIndex = 0;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: null,
body: Container(
padding: const EdgeInsets.all(100),
child: Row(
children: [
Icon(
MyIcons.home,
size: 100,
color: Colors.green,
),
Text("This is a ttf!"),
],
),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: currentIndex,
onTap: (index) {
_changePage(index);
},
selectedItemColor: Colors.green,
unselectedItemColor: Colors.black38,
backgroundColor: Colors.white,
iconSize: 40,
type: BottomNavigationBarType.fixed,
items: const [
BottomNavigationBarItem(
icon: Icon(MyIcons.home),
activeIcon: Icon(MyIcons.home),
label: " home page "),
BottomNavigationBarItem(
icon: Icon(MyIcons.life),
activeIcon: Icon(MyIcons.life),
label: " life "),
BottomNavigationBarItem(
icon: Icon(MyIcons.money),
activeIcon: Icon(MyIcons.money),
label: " conduct financial transactions "),
BottomNavigationBarItem(
icon: Icon(MyIcons.mine),
activeIcon: Icon(MyIcons.mine),
label: " my "),
]),
);
}
/* Switch pages */
void _changePage(int index) {
/* If the navigation item you click is not the current item Switch */
if (index != currentIndex) {
setState(() {
currentIndex = index;
});
}
}
}
Attribute meaning :
BottomNavigationBarItem-
icon: Default icon
activeIcon: Icon when selected
label: Text
backgroundColor:BottomNavigationBarType by shifting When the background color
BottomNavigationBar-
items: Collection of internal elements
currentIndex: Currently selected
backgroundColor: Background color
selectedItemColor: The color of the selected item in the picture and text
unselectedItemColor: Pictures and text not The color of the selection
iconSize: Icon size
type: Type of bottom navigation bar , Yes fixed and shifting Two types , The display effect is different
onTap: Click the callback function
2.2 Callback function
by ! What kind of thing is this ???
Don't worry. , To look down :
/// Called when one of the [items] is tapped.
///
/// The stateful widget that creates the bottom navigation bar needs to keep
/// track of the index of the selected [BottomNavigationBarItem] and call
/// `setState` to rebuild the bottom navigation bar with the new [currentIndex].
final ValueChanged<int>? onTap;
First look at the following definition : A modifier is defined, but final Of int type , be known as currentIndex Properties of .
/// The index into [items] for the current active [BottomNavigationBarItem].
final int currentIndex;
Okay , We use the source code , Observe the following :
/// Signature for callbacks that report that an underlying value has changed.
///
/// See also:
///
/// * [ValueSetter], for callbacks that report that a value has been set.
typedef ValueChanged<T> = void Function(T value);
final ValueChanged<int>? onTap;
Try to explain : Defines a modifier as final Callback function for , When int When the type value changes , Trigger callback .
2.3 Callback function example
import 'dart:io';
void main(){
BottomNavigationBar bar = BottomNavigationBar(
changed: (index){
print("index-->"+index);
}
);
print("sleep 3 s");
sleep(const Duration(seconds: 3));
bar.select("40");
}
// Alias function
typedef ValueChanged<T> = void Function(T value);
class BottomNavigationBar{
final ValueChanged<String>? changed;
BottomNavigationBar({
// ValueChanged<String>? this.changed,
this.changed,
});
// Change state
void select(String index){
print(this.changed == null);
//this.changed Not empty perform call;
// call Will be index field value , give ValueChanged, It can be understood that the value has changed , Then callback
this.changed?.call(index);
}
}
copyright notice
author[Xiang Yu Han],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/131/202205102051104450.html
The sidebar is recommended
- Which securities company does qiniu school recommend? Is it safe to open an account
- Hyperstyle: complete face inversion using hypernetwork
- What activities are supported by the metauniverse to access reality at this stage?
- P2P swap OTC trading on qredo
- Google | coca: the contrast caption generator is the basic image text model
- SIGIR 2022 | Huawei reloop: self correcting training recommendation system
- Whether you want "melon seed face" or "national character face", the "face changing" technology of Zhejiang University video can be done with one click!
- Sorting of naacl2022 prompt related papers
- Servlet create project
- "Chinese version" Musk was overturned by the original: "if it's true, I want to see him"
guess what you like
[network security] web security trends and core defense mechanisms
[intensive reading] object detection series (10) FPN: introducing multi-scale with feature pyramid
007. ISCSI server chap bidirectional authentication configuration
2021-03-09
plot_ Importance multi classification, sorting mismatch, image value not displayed
[intensive reading] object detection series (XI) retinanet: the pinnacle of one stage detector
How to install MFS environment for ECS
[intensive reading] the beginning of object detection series (XII) cornernet: anchor free
Open source sharing -- a record of students passing through time
MOT:A Higher Order Metric for Evaluating Multi-object Tracking
Random recommended
- How to develop a distributed memory database (1)
- Reverse engineers reverse restore app and code, and localization is like this
- One line command teaches you how to export all the libraries in anaconda
- Bi tools are relatively big. Let's see which one is most suitable for you
- Read the history of database development
- Self cultivation of coder - batterymanager design
- Technology application of swift phantom type phantom in Apple source code learning
- Swiftui advanced skills: what is the use of the technology of swift phantom type phantom
- Swiftui advanced animation Encyclopedia of complex deformation animation is based on accelerate and vector arithmetic (tutorial includes source code)
- What problems remain unsolved in swiftui in 2022
- I'll set the route for fluent
- Flutter drawing process analysis and code practice
- Emoji language commonly used icon collection (interesting Emoji)
- 5.14 comprehensive case 2.0 - automatic induction door
- How to deploy redis service on k8s top?
- Importance of data warehouse specification
- Idea automatically generates serialization ID
- Why is it recommended not to use select * in MySQL?
- Let's talk about why redis needs to store two data structures for the same data type?
- Domain lateral move RDP delivery
- gDvuGqjmDS
- [learn slam orb_slam2 or slam3 from scratch] summary of all blog articles
- 20000 + star ultra lightweight OCR system pp-ocrv3 effect increased by 5% - 11%!
- A configurable canvas clock - Super multi style
- The pp-ocrv3 effect of 20000 + star ultra lightweight OCR system is further improved by 5% - 11%
- MySQL's golden rule: "don't use select *"
- True interview question: why does redis store a data type twice?
- High threshold for large factories? Five exclusive PDFs inside Alibaba will take you forward and win the offer
- Is it really hard to find a job? How on earth can I find a job with high salary without worrying about being laid off
- How to design knowledge center? (code attached)
- OWASP top 10 vulnerability analysis
- Are you still writing comment templates manually? Idea can generate annotation templates of classes and methods with one click. Click in if you don't know
- Numpy core syntax and code sorting summary!
- Can you believe that the swoole timer can realize millisecond task scheduling?
- Detailed explanation of art template engine
- Telephone subsystem of openharmony source code analysis -- call flow
- Yixin Huachen: how to do a good job in digital transformation in the power industry?
- One stop collaboration is really delicious - apipost
- Notes on modern algebra and series of questions: Chapter 1 (introduction of algebraic system)
- Notes on modern algebra and serialization of question types: Chapter 2 (properties of binary operation)