to do using flutter
In this documentation, I will cover how you can create a TODO App using Flutter
Step 1
Open Android Studio and click on the Create New Flutter Project option.
Step 2
Select Flutter Application and click on Next.
Go to lib→main.dart File.
MAIN.DART
- import ‘package:flutter/material.dart’;
- import ‘package:flutter_todoapp_getx/screens/notes_list.dart’;
- import ‘package:get/get.dart’;
- import ‘package:get_storage/get_storage.dart’;
- void main() async {
- await GetStorage.init();
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return GetMaterialApp(
- title: ‘Flutter Demo’,
- theme: ThemeData(
- primarySwatch: Colors.red,
- visualDensity: VisualDensity.adaptivePlatformDensity,
- ),
- home: NoteList(),
- );
- }
- }
Since we are going to use the navigation system of GETX and other alerts and snackbar that’s why we have converted MaterialApp to GetMaterialApp and we have provided our home screen as NoteList().
Create a new Dart file in lib folder and name it as model.dart and paste the following code in model.dart File.
- class Note {
- String title;
- Note({
- this.title
- });
- factory Note.fromJson(Map < String, dynamic > json) => Note(
- title: json[‘title’]);
- Map < String, dynamic > toJson() => {
- ‘title’: title
- };
- }
Create a New Dart File in lib→screens Folder and name it as notes_list.dart and Paste the following code in notes_list.dart File.
- import ‘package:flutter/material.dart’;
- import ‘package:get/get.dart’;
- import ‘package:flutter_todoapp_getx/screens/my_note.dart’;
- import ‘controller.dart’;
- class NoteList extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- final NoteController nc = Get.put(NoteController());
- Widget getNoteList() {
- return Obx(
- () => nc.notes.length == 0 ? Center(child: Image.asset(‘assets/lists.jpeg’), ) :
- ListView.builder(
- itemCount: nc.notes.length,
- itemBuilder: (context, index) =>
- Card(
- child: ListTile(
- title: Text(nc.notes[index].title,
- style: TextStyle(
- fontWeight: FontWeight.w500)),
- leading: Text(
- (index + 1).toString() + “.”,
- style: TextStyle(fontSize: 15),
- ),
- trailing: Wrap(children: < Widget > [
- IconButton(
- icon: Icon(Icons.create),
- onPressed: () =>
- Get.to(MyNote(index: index))),
- IconButton(
- icon: Icon(Icons.delete),
- onPressed: () {
- Get.defaultDialog(
- title: ‘Delete Note’,
- middleText: nc.notes[index].title,
- onCancel: () => Get.back(),
- confirmTextColor: Colors.white,
- onConfirm: () {
- nc.notes.removeAt(index);
- Get.back();
- });
- })
- ])),
- )
- ),
- );
- }
- return SafeArea(
- child: Scaffold(
- backgroundColor: Colors.white,
- appBar: AppBar(
- centerTitle: true,
- title: Text(‘Todo App’),
- ),
- floatingActionButton: FloatingActionButton(
- child: Icon(Icons.add),
- onPressed: () {
- Get.to(MyNote());
- },
- ),
- body: Container(
- child: Padding(
- padding: EdgeInsets.all(5),
- child: getNoteList()),
- )));
- }
- }
REFERENCE:https://www.c-sharpcorner.com/article/an-introduction-to-programming-through-cpp/