Skip to content

Commit

Permalink
Article header
Browse files Browse the repository at this point in the history
  • Loading branch information
Yustas committed Jan 7, 2025
1 parent 823c4fe commit 30d73e7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 70 deletions.
43 changes: 19 additions & 24 deletions lib/screens/pravopys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,28 @@ import 'package:mova/widgets/header.dart';
import 'package:mova/widgets/content_list.dart';
import 'package:mova/widgets/articles_list.dart';
import 'package:mova/utils/search.dart';
import 'package:mova/utils/controllers.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';

class Pravopys extends StatefulWidget {
class Pravopys extends StatelessWidget {
const Pravopys({super.key, required this.content, required this.prevContent});

final Content content;
final Content? prevContent;

@override
State<Pravopys> createState() => _PravopysState();
}

class _PravopysState extends State<Pravopys> {
final ScrollPositionController _scrollController = ScrollPositionController();

void onScroll(ScrollPosition scrollPosition) {
_scrollController.doScroll!(scrollPosition);
}

@override
Widget build(BuildContext context) {
final Future<PageData> pageData =
loadPage(parentContentId: widget.content.id);
loadPage(parentContentId: content.id);

String getContentData(Content content) {
return content.prefix.isNotEmpty
? "${content.prefix} ${content.data}"
: content.data;
}

var isFirstScreen = widget.prevContent == null;
var header = getContentData(widget.content);
var appBarTitle = isFirstScreen ? '' : getContentData(widget.prevContent!);
var isFirstScreen = prevContent == null;
var header = getContentData(content);
var appBarTitle = isFirstScreen ? '' : getContentData(prevContent!);
var actions = [
IconButton(
icon: const Icon(Icons.search),
Expand Down Expand Up @@ -81,23 +69,30 @@ class _PravopysState extends State<Pravopys> {
),
body: Column(
children: [
Header(title: header, searchBar: isFirstScreen, scrollController: _scrollController,),
Expanded(
child: FutureBuilder<PageData>(
future: pageData,
builder: (BuildContext context, AsyncSnapshot<PageData> snapshot) {
if (snapshot.hasData) {
var content = snapshot.data!.content;
var links = snapshot.data!.content;
var articles = snapshot.data!.articles;

if (content.isNotEmpty) {
return ContentList(
content: content, prevPage: widget.content);
if (links.isNotEmpty) {
return Column(
children: [
Header(title: header, searchBar: isFirstScreen),
Expanded(
child: ContentList(
content: links, prevPage: content),
),
],
);
} else {
return ArticlesList(
header: header,
articles: articles,
content: widget.content,
onScroll: onScroll);
content: content,
);
}
} else if (snapshot.hasError) {
return Error(message: 'Error: ${snapshot.error}');
Expand Down
11 changes: 9 additions & 2 deletions lib/themes/material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,21 @@ class MaterialTheme {
fontWeight: FontWeight.w800,
color: colorScheme.onSurface
),
// # Heading 2
headlineMedium: ThemeData()
.textTheme
.headlineMedium!
.copyWith(
fontSize: 24,
fontWeight: FontWeight.w800,
color: colorScheme.onSurface
),
headlineSmall:
ThemeData().textTheme.headlineSmall!.copyWith(fontSize: 24),
// Tinos height: 1.3,

bodyMedium: GoogleFonts.roboto(textStyle: ThemeData().textTheme.bodyMedium!.copyWith(
fontSize: 18,
color: colorScheme.onSurfaceVariant,
// height: 1.3,
)),
bodySmall: ThemeData().textTheme.bodySmall!.copyWith(fontSize: 15),
);
Expand Down
74 changes: 34 additions & 40 deletions lib/widgets/articles_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,13 @@ import '../models/article.dart';
import 'package:mova/themes//markdown.dart';
import 'package:flutter_markdown/flutter_markdown.dart';

class ArticlesList extends StatefulWidget {
class ArticlesList extends StatelessWidget {
const ArticlesList(
{super.key, required this.articles, required this.content, required this.onScroll});
{super.key, required this.articles, required this.content, required this.header});

final String header;
final List<Article> articles;
final Content content;
final void Function(ScrollPosition) onScroll;

@override
State<ArticlesList> createState() => _ArticlesListState();
}

class _ArticlesListState extends State<ArticlesList> {

final ScrollController _scrollController = ScrollController();

_scrollListener() {
widget.onScroll(_scrollController.position);
}

@override
void initState() {
_scrollController.addListener(_scrollListener);
super.initState();
}

@override
Widget build(BuildContext context) {
Expand All @@ -44,32 +26,44 @@ class _ArticlesListState extends State<ArticlesList> {
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) =>
Pravopys(content: nextContent, prevContent: widget.content),
Pravopys(content: nextContent, prevContent: content),
),
); // Navigator.push(context, route)
}
}

return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: ListView.builder(
//controller: _scrollController,
scrollDirection: Axis.vertical,
itemCount: widget.articles.length,
itemBuilder: (context, index) {
return Column(
children: [
MarkdownBody(
data: widget.articles[index].body,
onTapLink: (text, url, title) {
openContent(context, text);
},
styleSheet: stylesheet(context),
),
const SizedBox(height: 10)
],
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10,),
Text(
header,
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 10,),
Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: articles.length,
itemBuilder: (context, index) {
return Column(
children: [
MarkdownBody(
data: articles[index].body,
onTapLink: (text, url, title) {
openContent(context, text);
},
styleSheet: stylesheet(context),
),
const SizedBox(height: 10)
],
);
},
),
),
],
),
);
}
Expand Down
5 changes: 1 addition & 4 deletions lib/widgets/header.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import 'package:flutter/material.dart';
import 'package:mova/utils/controllers.dart';
import 'package:mova/widgets/search.dart';

class Header extends StatelessWidget {
const Header(
{super.key,
required this.title,
required this.searchBar,
required this.scrollController});
required this.searchBar});

final String title;
final bool searchBar;
final ScrollPositionController scrollController;

final double? fontSize = 24;

Expand Down

0 comments on commit 30d73e7

Please sign in to comment.