Here’s an example of a basic note-taking app in Flutter:

import ‘package:flutter/material.dart’;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: ‘Note App’,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: NoteList(),
);
}
}

class NoteList extends StatefulWidget {
@override
_NoteListState createState() => _NoteListState();
}

class _NoteListState extends State<NoteList> {
List<String> _notes = [];

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘Note App’),
),
body: ListView.builder(
itemCount: _notes.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(_notes[index]),
trailing: IconButton(
icon: Icon(Icons.delete),
onPressed: () {
setState(() {
_notes.removeAt(index);
});
},
),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(‘Add note’),
content: TextField(
onSubmitted: (value) {
setState(() {
_notes.add(value);
});
Navigator.of(context).pop();
},
),
actions: <Widget>[
FlatButton(
child: Text(‘Cancel’),
onPressed: () {
Navigator.of(context).pop();

 

In this example, a NoteList widget is created which extends StatefulWidget. The state of the widget is managed by _NoteListState. The _notes list stores the notes. The UI consists of a list of the notes and a floating action button to add new notes to the list. When the floating action button is pressed, a dialog pops up to allow the user to enter the text of a new note, which is then added to the _notes list. The list of notes is displayed using a ListView.builder. Each note in the list has a delete icon, which removes the note from the _notes list when pressed.

Facebook Comments Box
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments