Skip to content

Commit

Permalink
update some ui, fix storage_fake and pop while compose
Browse files Browse the repository at this point in the history
  • Loading branch information
tbm98 committed Oct 20, 2021
1 parent 7142025 commit c2971e5
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 60 deletions.
10 changes: 9 additions & 1 deletion lib/src/core/storage/fake_storage.dart
Expand Up @@ -4,11 +4,13 @@ import 'package:notes/src/core/storage/storage.dart';
import 'package:notes/src/models/note_model.dart';

class FakeStorage extends Storage {
bool _isFirstTime = true;
final List<NoteModel> _notes = [];
final StreamController<List<NoteModel>> _notesController =
new StreamController<List<NoteModel>>.broadcast();
StreamController<List<NoteModel>>.broadcast();

Stream<List<NoteModel>> get _notesStream => _notesController.stream;

Sink<List<NoteModel>> get _notesSink => _notesController.sink;

@override
Expand All @@ -20,6 +22,12 @@ class FakeStorage extends Storage {

@override
Stream<List<NoteModel>> allNoteStream() {
// fake a data event on first time
Future(() {
if (_isFirstTime) {
_notesSink.add(_notes);
}
});
return _notesStream;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/src/di/get_it.dart
Expand Up @@ -20,10 +20,9 @@ void setupGetIt() {
getIt.registerFactory<ShareHandler>(() => ShareHandlerDefault());
}

void setupGetItFake(){
void setupGetItFake() {
getIt.registerLazySingleton<Auth>(() => FakeAuth());
getIt.registerLazySingleton<Storage>(
() => FakeStorage());
getIt.registerLazySingleton<Storage>(() => FakeStorage());
getIt.registerLazySingleton<Notifications>(() => LocalNotifications());
getIt.registerFactory<ShareHandler>(() => ShareHandlerDefault());
}
4 changes: 1 addition & 3 deletions lib/src/ui/dialogs/profile.dart
Expand Up @@ -32,9 +32,7 @@ class ProfileDialog extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
return Container(
decoration: BoxDecoration(
color: Theme.of(context).canvasColor,
borderRadius: BorderRadius.circular(16)),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(16)),
padding: const EdgeInsets.all(8),
width: MediaQuery.of(context).size.width * 0.8,
child: Column(
Expand Down
93 changes: 50 additions & 43 deletions lib/src/ui/screens/compose/compose_page.dart
Expand Up @@ -51,51 +51,58 @@ class _AddNotePageState extends ConsumerState<ComposePage> {
composeState.noteModel.subTitle.isNotEmpty) {
_noteController.text = composeState.noteModel.subTitle;
}
return Scaffold(
appBar: AppBar(
leading: BackButton(onPressed: _handleReturn),
actions: [
const _ComposeAction(),
IconButton(onPressed: _handleReturn, icon: const Icon(Icons.done))
],
),
body: SizedBox.expand(
child: GestureDetector(
onTap: () {
_contentFocusNode.requestFocus();
},
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _titleController,
decoration: const InputDecoration(
hintText: 'Title',
border: InputBorder.none,
return WillPopScope(
onWillPop: () {
_handleReturn();
return Future.value(true);
},
child: Scaffold(
appBar: AppBar(
leading: const BackButton(),
actions: [
const _ComposeAction(),
IconButton(onPressed: _handleReturn, icon: const Icon(Icons.done))
],
),
body: SizedBox.expand(
child: GestureDetector(
onTap: () {
_contentFocusNode.requestFocus();
},
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _titleController,
decoration: const InputDecoration(
hintText: 'Title',
border: InputBorder.none,
),
maxLines: null,
style: const TextStyle(fontSize: 24),
textInputAction: TextInputAction.done,
autofocus: true,
onSubmitted: (_) => _contentFocusNode.requestFocus(),
onChanged:
ref.read(composeProvider.notifier).changedTitle,
),
maxLines: null,
style: const TextStyle(fontSize: 24),
textInputAction: TextInputAction.done,
autofocus: true,
onSubmitted: (_) => _contentFocusNode.requestFocus(),
onChanged: ref.read(composeProvider.notifier).changedTitle,
),
const NoticeNoteInfoWidget(),
TextField(
controller: _noteController,
decoration: const InputDecoration(
hintText: 'Note',
border: InputBorder.none,
const NoticeNoteInfoWidget(),
TextField(
controller: _noteController,
decoration: const InputDecoration(
hintText: 'Note',
border: InputBorder.none,
),
maxLines: null,
textInputAction: TextInputAction.newline,
focusNode: _contentFocusNode,
onChanged: ref.read(composeProvider.notifier).changedNote,
),
maxLines: null,
textInputAction: TextInputAction.newline,
focusNode: _contentFocusNode,
onChanged: ref.read(composeProvider.notifier).changedNote,
),
],
],
),
),
),
),
Expand Down
1 change: 0 additions & 1 deletion lib/src/ui/screens/compose/compose_state.dart
Expand Up @@ -21,4 +21,3 @@ class ComposeState with _$ComposeState {
factory ComposeState.fromJson(Map<String, dynamic> json) =>
_$ComposeStateFromJson(json);
}

6 changes: 4 additions & 2 deletions lib/src/ui/screens/todo/todo_page.dart
Expand Up @@ -87,8 +87,10 @@ class _SectionFinishedTodoList extends StatelessWidget {
Container(
width: double.infinity,
padding: const EdgeInsets.all(8),
color: Theme.of(context).primaryColor.withAlpha(255 ~/ 4),
child: Text(title)),
child: Text(
title,
style: Theme.of(context).textTheme.headline6,
)),
_TodoListRaw(
noteModels: todos,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ui/screens/trash/trash_page.dart
Expand Up @@ -88,7 +88,7 @@ class _TrashListRaw extends ConsumerWidget {
? const TextStyle(decoration: TextDecoration.lineThrough)
: const TextStyle();
return ListTile(
tileColor: finished ? Colors.green : null,
enabled: !finished,
title: Text(
noteModels[index].title,
style: textStyle,
Expand Down
6 changes: 2 additions & 4 deletions lib/src/ui/widgets/avatar_widget.dart
Expand Up @@ -39,7 +39,7 @@ class SignedInAvatar extends ConsumerWidget {
showProfileDialog(context);
},
child: user.avatarUrl == null
? const GuestAvatar()
? const IgnorePointer(child: GuestAvatar())
: ClipOval(
child: CachedNetworkImage(
imageUrl: user.avatarUrl ?? '',
Expand Down Expand Up @@ -68,9 +68,7 @@ class GuestAvatar extends ConsumerWidget {
ref.read(profileProvider.notifier).signIn();
},
child: const CircleAvatar(
backgroundColor: Colors.yellow,
radius: 20,
child: Text('A')),
backgroundColor: Colors.yellow, radius: 20, child: Text('A')),
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Expand Up @@ -932,5 +932,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.14.2 <3.0.0"
flutter: ">=2.5.1"
dart: ">=2.14.0 <3.0.0"
flutter: ">=2.5.0"

0 comments on commit c2971e5

Please sign in to comment.