n_dimensional_array 1.0.5
n_dimensional_array: ^1.0.5 copied to clipboard
Allows for the creation and easy manipulation of n-dimensional arrays in Dart.
import 'package:flutter/material.dart';
import 'package:n_dimensional_array/n_dimensional_array.dart';
void main() => runApp(const ArrayExample());
class ArrayExample extends StatefulWidget {
const ArrayExample({super.key});
@override
State<ArrayExample> createState() => _ArrayExampleState();
}
class _ArrayExampleState extends State<ArrayExample> {
NdArray _array = NdArray.fromList([
[1, 2],
[3, 4],
]);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'n-Dimensional Array',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: Scaffold(
appBar: AppBar(title: const Text('n-Dimensional Array')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Shape: ${_array.shape}'),
Text('Data: ${_array.data}'),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => setState(() => _array[0][0] += 1),
child: const Text('Increment [0][0]'),
),
ElevatedButton(
onPressed: () => setState(
() => _array.reshape([-1, _array.shape.last + 1]),
),
child: const Text('Add column'),
),
ElevatedButton(
onPressed: () => setState(() {
_array = NdArray.fromList([
[1, 2],
[3, 4],
]);
}),
child: const Text('Reset'),
),
],
),
),
),
);
}
}