83 lines
2.2 KiB
Dart
83 lines
2.2 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||
|
import 'package:fnotes/theme_bloc.dart';
|
||
|
|
||
|
class Notes extends StatefulWidget {
|
||
|
const Notes({
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
@override
|
||
|
State<Notes> createState() => _NotesState();
|
||
|
}
|
||
|
|
||
|
class _NotesState extends State<Notes> {
|
||
|
List<String> notes = List.empty(growable: true);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
title: const Text('Your notes:'),
|
||
|
actions: [
|
||
|
IconButton(
|
||
|
icon: const Icon(Icons.light_mode),
|
||
|
onPressed: () {
|
||
|
context.read<ThemeBloc>().add(ThemeEvent());
|
||
|
},
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
body: BlocBuilder<ThemeBloc, ThemeState>(
|
||
|
builder: (context, state) {
|
||
|
return ListView.builder(
|
||
|
itemCount: notes.length,
|
||
|
itemBuilder: (context, index) {
|
||
|
return Dismissible(
|
||
|
onDismissed: (direction) {
|
||
|
setState(() {
|
||
|
notes.removeAt(index);
|
||
|
});
|
||
|
},
|
||
|
key: ValueKey(notes[index]),
|
||
|
child: Card(
|
||
|
elevation: 5,
|
||
|
color: state.theme.colorScheme.primaryContainer,
|
||
|
child: SizedBox(
|
||
|
height: 50,
|
||
|
child: Padding(
|
||
|
padding: const EdgeInsets.only(left: 20),
|
||
|
child: Align(
|
||
|
alignment: Alignment.centerLeft,
|
||
|
child: Text(
|
||
|
notes[index],
|
||
|
style: TextStyle(
|
||
|
color:
|
||
|
state.theme.colorScheme.onPrimaryContainer),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
},
|
||
|
),
|
||
|
floatingActionButton: FloatingActionButton(
|
||
|
onPressed: () {
|
||
|
setState(() {
|
||
|
addNote();
|
||
|
});
|
||
|
},
|
||
|
child: const Icon(Icons.add)),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
int devCounter = 0;
|
||
|
void addNote() {
|
||
|
notes.add('Hallo $devCounter');
|
||
|
devCounter++;
|
||
|
}
|
||
|
}
|