database_device 0.0.4 copy "database_device: ^0.0.4" to clipboard
database_device: ^0.0.4 copied to clipboard

Equipped and easy database.

example/example.dart

import 'package:flutter/material.dart';
import 'package:database_device/database_device.dart';

void main() {
  runApp(const MyApp());
}

//===================================
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Database Device',
      debugShowCheckedModeBanner: false,
      home: DatabaseDeviceWidget(),
    );
  }
}

class DatabaseDeviceWidget extends StatefulWidget {
  const DatabaseDeviceWidget({Key? key}) : super(key: key);

  @override
  State<DatabaseDeviceWidget> createState() => _DatabaseDeviceWidgetState();
}

class _DatabaseDeviceWidgetState extends State<DatabaseDeviceWidget> {
  getLingthChar() async {
    int a = await DatabaseDevice.lengthChar;
    characterCount = a;
  }

  List list = [];
  int characterCount = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Database Device"),
        actions: [
          IconButton(
            onPressed: () => DatabaseDevice.removeAllData(),
            icon: const Icon(Icons.delete),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add),
        onPressed: () => DatabaseDevice.add(
          Description(
            age: 22,
            name: 'Raed',
          ).toMap(),
        ),
      ),
      body: DatabaseDevice.childFutureBuilder(
        getData: (data) {
          setState(() {
            list = data;

            getLingthChar();
          });
        },
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
                padding: const EdgeInsets.all(12),
                child: Text("Character count = $characterCount")),
            Expanded(
              flex: 1,
              child: ReorderableListView.builder(
                onReorder: (oldIndex, newIndex) =>
                    DatabaseDevice.moveIteam(oldIndex, newIndex),
                itemCount: list.length,
                itemBuilder: ((context, index) => Card(
                      key: ValueKey(index),
                      elevation: 7,
                      color: Colors.amber.shade400,
                      child: Column(
                        children: [
                          Container(
                            alignment: Alignment.center,
                            height: 100,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: [
                                Text(list[index]['key'].toString()),
                                Text(list[index]['name']),
                                Text(list[index]['age'].toString()),
                              ],
                            ),
                          ),
                          Container(
                            height: 50,
                            color: Colors.amber.shade100,
                            child: Row(
                              children: [
                                IconButton(
                                  onPressed: () =>
                                      DatabaseDevice.removeRow(index),
                                  icon: const Icon(Icons.delete),
                                ),
                                IconButton(
                                  onPressed: () =>
                                      DatabaseDevice.copyAddPast(index),
                                  icon: const Icon(Icons.copy),
                                ),
                                TextButton(
                                  onPressed: () => DatabaseDevice.editeFild(
                                    index,
                                    {
                                      "name": 'Ali',
                                    },
                                  ),
                                  child: const Text('edite name'),
                                ),
                                IconButton(
                                  onPressed: () => DatabaseDevice.editeRow(
                                    index,
                                    Description(
                                      age: 33,
                                      name: 'Anas',
                                    ).toMap(),
                                  ),
                                  icon: const Icon(Icons.edit),
                                ),
                              ],
                            ),
                          )
                        ],
                      ),
                    )),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class User {
  int idCard;
  Description description;
  User({
    required this.idCard,
    required this.description,
  });

  Map<String, dynamic> toMap() {
    return {
      'idCard': idCard,
      'description': description.toMap(),
    };
  }

  factory User.fromMap(Map<String, dynamic> map) {
    return User(
      idCard: map['idCard']?.toInt() ?? 0,
      description: Description.fromMap(map['description']),
    );
  }
}

class Description {
  String name;
  int age;
  Description({
    required this.name,
    required this.age,
  });

  Map<String, dynamic> toMap() {
    return {
      'name': name,
      'age': age,
    };
  }

  factory Description.fromMap(Map<String, dynamic> map) {
    return Description(
      name: map['name'] ?? '',
      age: map['age']?.toInt() ?? 0,
    );
  }
}
0
likes
120
pub points
0%
popularity

Publisher

unverified uploader

Equipped and easy database.

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on database_device