-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7525ca4
commit aa7536d
Showing
6 changed files
with
310 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:all_in_one/isar/article.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
typedef OnArticleSelected = void Function(Article); | ||
|
||
class ArticleItem extends ConsumerStatefulWidget { | ||
const ArticleItem( | ||
{super.key, required this.article, required this.onArticleSelected}); | ||
final Article article; | ||
final OnArticleSelected onArticleSelected; | ||
|
||
@override | ||
ConsumerState<ArticleItem> createState() => _ArticleItemState(); | ||
} | ||
|
||
class _ArticleItemState extends ConsumerState<ArticleItem> { | ||
bool isHovering = false; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MouseRegion( | ||
cursor: SystemMouseCursors.click, | ||
onEnter: (event) { | ||
setState(() { | ||
isHovering = true; | ||
}); | ||
}, | ||
onExit: (event) { | ||
setState(() { | ||
isHovering = false; | ||
}); | ||
}, | ||
child: GestureDetector( | ||
onTap: () { | ||
widget.onArticleSelected(widget.article); | ||
}, | ||
child: Container( | ||
height: 40, | ||
decoration: BoxDecoration( | ||
color: isHovering | ||
? const Color.fromARGB(255, 197, 195, 227).withAlpha(100) | ||
: Colors.transparent, | ||
borderRadius: BorderRadius.circular(5)), | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
flex: 1, | ||
child: Text( | ||
widget.article.title, | ||
maxLines: 1, | ||
softWrap: true, | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
), | ||
Expanded( | ||
flex: 1, | ||
child: Text( | ||
DateTime.fromMillisecondsSinceEpoch(widget.article.createAt) | ||
.toString() | ||
.split(".") | ||
.first, | ||
maxLines: 1, | ||
softWrap: true, | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import 'package:all_in_one/llm/editor/components/article_item.dart'; | ||
import 'package:all_in_one/llm/editor/notifiers/article_notifier.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class LoadArticleDialog extends ConsumerStatefulWidget { | ||
const LoadArticleDialog({super.key}); | ||
|
||
@override | ||
ConsumerState<LoadArticleDialog> createState() => _LoadArticleDialogState(); | ||
} | ||
|
||
class _LoadArticleDialogState extends ConsumerState<LoadArticleDialog> { | ||
@override | ||
Widget build(BuildContext context) { | ||
final state = ref.watch(articleProvider); | ||
|
||
return Material( | ||
elevation: 10, | ||
borderRadius: BorderRadius.circular(20), | ||
child: Container( | ||
padding: const EdgeInsets.all(20), | ||
width: MediaQuery.of(context).size.width * 0.8, | ||
height: MediaQuery.of(context).size.height * 0.8, | ||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20)), | ||
child: state.when( | ||
data: (v) { | ||
if (v.isEmpty) { | ||
return const Center( | ||
child: Text("There is no template created."), | ||
); | ||
} | ||
|
||
return Column( | ||
children: [ | ||
const SizedBox( | ||
height: 50, | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
flex: 1, | ||
child: Text("name"), | ||
), | ||
Expanded( | ||
flex: 1, | ||
child: Text("create at"), | ||
) | ||
], | ||
), | ||
), | ||
Expanded( | ||
child: ListView.builder( | ||
itemBuilder: (c, i) { | ||
return ArticleItem( | ||
article: v[i], | ||
onArticleSelected: (p0) { | ||
Navigator.of(context).pop(p0); | ||
}, | ||
); | ||
}, | ||
itemCount: v.length, | ||
)), | ||
], | ||
); | ||
}, | ||
error: (_, s) { | ||
return Center( | ||
child: Text(s.toString()), | ||
); | ||
}, | ||
loading: () => const Center( | ||
child: CircularProgressIndicator(), | ||
)), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:all_in_one/isar/article.dart'; | ||
import 'package:all_in_one/isar/database.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:isar/isar.dart'; | ||
|
||
class ArticleNotifier extends AutoDisposeAsyncNotifier<List<Article>> { | ||
final IsarDatabase isarDatabase = IsarDatabase(); | ||
|
||
@override | ||
FutureOr<List<Article>> build() async { | ||
final articles = await isarDatabase.isar!.articles | ||
.where() | ||
.sortByCreateAtDesc() | ||
.findAll(); | ||
return articles; | ||
} | ||
|
||
Future<Article?> getLast() async { | ||
return await isarDatabase.isar!.articles | ||
.where() | ||
.sortByCreateAtDesc() | ||
.findFirst(); | ||
} | ||
} | ||
|
||
final articleProvider = | ||
AutoDisposeAsyncNotifierProvider<ArticleNotifier, List<Article>>(() { | ||
return ArticleNotifier(); | ||
}); |
Oops, something went wrong.