Step by step instructions to make a Fibonacci list utilizing vacillate and dart. To start with, we will import the essential ripple bundle material.dart.
Fibonacci is most popular for the rundown of numbers called the Fibonacci Sequence. The rundown never stops, however it begins thusly: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... In this rundown, an individual can locate the following number by including the last two numbers together.

Here runApp is the main root of our App. It includes MaterialApp. MaterialApp Contains appBar which is shown above the page which contains some texts and settings or drawer icons usually.
MaterialApp has other two values, home, and body.
The body returns FibonacciListView() class which has the actual code for Fibonacci math.
import import import 'package:flutter/material.dart';
void main() async {
final numbers = FibonacciNumbers();
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('Fibonacci List'),
),
body: FibonacciListView(numbers),
),
),
);
};The Class FibonacciNumbers has an if statement.
import class FibonacciNumbers {
final cache = {0: BigInt.from(1), 1: BigInt.from(1)};
BigInt get(int i) {
if (!cache.containsKey(i)) {
cache[i] = get(i - 1) + get(i - 2);
}
return cache[i];
}
};Here is the FibonacciListView statelessWidget class.
class FibonacciListView extends StatelessWidget {
final FibonacciNumbers numbers;
FibonacciListView(this.numbers);
@override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (context, i) {
return ListTile(
title: Text('${numbers.get(i)}'),
onTap: () {
final snack = SnackBar(
content: Text('${numbers.get(i)} is '
'#$i in the Fibonacci sequence!'),
);
Scaffold.of(context).showSnackBar(snack);
},
);
},
);
}
};
0 Comments
Welcome! Please Comment Without Any Hesitation.
Thank You