-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from mylxsw/develop
Develop
- Loading branch information
Showing
14 changed files
with
582 additions
and
29 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
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
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
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,53 @@ | ||
import 'package:askaide/helper/logger.dart'; | ||
import 'package:askaide/repo/api/notification.dart'; | ||
import 'package:askaide/repo/api_server.dart'; | ||
import 'package:loading_more_list/loading_more_list.dart'; | ||
|
||
class NotificationDatasource extends LoadingMoreBase<NotifyMessage> { | ||
int startId = 0; | ||
bool _hasMore = true; | ||
bool forceRefresh = false; | ||
|
||
NotificationDatasource(); | ||
|
||
@override | ||
bool get hasMore => _hasMore || forceRefresh; | ||
|
||
@override | ||
Future<bool> loadData([bool isloadMoreAction = false]) async { | ||
try { | ||
final messages = | ||
await APIServer().notifications(startId: startId, cache: false); | ||
|
||
if (startId == 0) { | ||
clear(); | ||
} | ||
|
||
for (var element in messages.data) { | ||
add(element); | ||
} | ||
|
||
if (messages.data.isEmpty) { | ||
_hasMore = false; | ||
} | ||
|
||
startId = messages.lastId; | ||
return true; | ||
} catch (e) { | ||
Logger.instance.e(e); | ||
return false; | ||
} | ||
} | ||
|
||
@override | ||
Future<bool> refresh([bool notifyStateChanged = false]) async { | ||
_hasMore = true; | ||
startId = 0; | ||
//force to refresh list when you don't want clear list before request | ||
//for the case, if your list already has 20 items. | ||
forceRefresh = !notifyStateChanged; | ||
var result = await super.refresh(notifyStateChanged); | ||
forceRefresh = false; | ||
return result; | ||
} | ||
} |
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,126 @@ | ||
import 'package:askaide/helper/ability.dart'; | ||
import 'package:askaide/page/component/background_container.dart'; | ||
import 'package:askaide/page/component/chat/markdown.dart'; | ||
import 'package:askaide/page/component/column_block.dart'; | ||
import 'package:askaide/page/component/theme/custom_size.dart'; | ||
import 'package:askaide/page/component/theme/custom_theme.dart'; | ||
import 'package:askaide/repo/api/article.dart'; | ||
import 'package:askaide/repo/api_server.dart'; | ||
import 'package:askaide/repo/settings_repo.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:url_launcher/url_launcher_string.dart'; | ||
|
||
class ArticleScreen extends StatefulWidget { | ||
final SettingRepository settings; | ||
final int id; | ||
const ArticleScreen({super.key, required this.settings, required this.id}); | ||
|
||
@override | ||
State<ArticleScreen> createState() => _ArticleScreenState(); | ||
} | ||
|
||
class _ArticleScreenState extends State<ArticleScreen> { | ||
Article article = Article( | ||
id: 0, | ||
title: '标题', | ||
content: '内容', | ||
); | ||
|
||
@override | ||
void initState() { | ||
APIServer().article(id: widget.id).then((value) { | ||
setState(() { | ||
article = value; | ||
}); | ||
}); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final customColors = Theme.of(context).extension<CustomColors>()!; | ||
|
||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text( | ||
article.title, | ||
style: const TextStyle(fontSize: CustomSize.appBarTitleSize), | ||
), | ||
toolbarHeight: CustomSize.toolbarHeight, | ||
centerTitle: true, | ||
leading: IconButton( | ||
icon: Icon( | ||
Icons.close, | ||
color: customColors.weakLinkColor, | ||
), | ||
onPressed: () { | ||
if (context.canPop()) { | ||
context.pop(); | ||
} else { | ||
context.go(Ability().homeRoute); | ||
} | ||
}, | ||
), | ||
), | ||
backgroundColor: customColors.backgroundContainerColor, | ||
body: BackgroundContainer( | ||
setting: widget.settings, | ||
child: SafeArea( | ||
top: false, | ||
child: Container( | ||
padding: const EdgeInsets.symmetric(horizontal: 10), | ||
child: SingleChildScrollView( | ||
child: ColumnBlock( | ||
padding: | ||
const EdgeInsets.symmetric(horizontal: 15, vertical: 15), | ||
children: [ | ||
Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
Text( | ||
'作者:${article.author ?? '管理员'}', | ||
style: TextStyle( | ||
fontSize: 12, | ||
color: customColors.weakTextColor, | ||
), | ||
), | ||
if (article.createdAt != null) | ||
Text( | ||
DateFormat('yyyy/MM/dd HH:mm') | ||
.format(article.createdAt!.toLocal()), | ||
style: TextStyle( | ||
fontSize: 12, | ||
color: | ||
customColors.weakTextColor?.withAlpha(100), | ||
), | ||
), | ||
], | ||
), | ||
const SizedBox(height: 10), | ||
Markdown( | ||
data: article.content, | ||
onUrlTap: (value) { | ||
if (value.startsWith("aidea-app://")) { | ||
var route = value.substring('aidea-app://'.length); | ||
context.push(route); | ||
} else { | ||
launchUrlString(value); | ||
} | ||
}, | ||
), | ||
], | ||
) | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.