Article page
import 'package:flutter/material.dart';
import 'package:share/share.dart';
import'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
class ArticlePage extends StatelessWidget {
final data;
const ArticlePage({Key? key, required this.data}) : super(key: key);
// Share article
final String _content = "Condividi l'app con i tuoi contatti";
void _shareContent() {Share.share(_content);}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
leading: Builder(
builder: (BuildContext context) {
return GestureDetector(
child: Center(
child: Container(
color: Colors.white70.withOpacity(0),
child: Container(
height: 30,
width: 30,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/previous.png',
),
),
),
),
),
),
onTap: () {
Navigator.of(context).pop();
},
);
},
),
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
background: Image.network(data["_embedded"]["wp:featuredmedia"][0]["source_url"], fit: BoxFit.cover,),
),
floating: true,
expandedHeight: 320,
actions: <Widget>[
IconButton(
onPressed: _shareContent,
color: Colors.blue.shade900,
iconSize: 35,
icon: const SizedBox(
child: Image(
image: AssetImage('assets/images/share-icon.png',), fit: BoxFit.cover,
),
height: 30, width: 30,
),
),
],
),
SliverList(
delegate: SliverChildListDelegate([
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 20,),
// Title container
Container(
padding: const EdgeInsets.all(16),
child: Text(data['title']['rendered']
.toString()
.replaceAll("<p>", "")
.replaceAll("</p>", ""),
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 20,
fontFamily: "Raleway",
),
),
),
const SizedBox(height: 0),
Container(
padding: const EdgeInsets.all(16),
child: HtmlWidget(
data['content']['rendered'],
),
),
const SizedBox(height: 20),
],
),
],
),
),
],
),
);
}
}
class SearchBar extends SearchDelegate{@override String get searchFieldLabel => "Cerca articolo";
@override
ThemeData appBarTheme(BuildContext context) {
return Theme.of(context).copyWith(
appBarTheme: const AppBarTheme(color: Color(0xFF0D47A1),),
accentColor: Colors.white,
textSelectionTheme: const TextSelectionThemeData(cursorColor: Color(0xFFFFFFFF),
),
textTheme: const TextTheme(
headline1: TextStyle(color: Colors.black,),
headline2: TextStyle(color: Colors.black,),
bodyText1: TextStyle(color: Colors.black,),
),
inputDecorationTheme: const InputDecorationTheme(
isDense: true,// this will remove the default content padding
alignLabelWithHint: true,
),
);
}
List suggestions = [ 'Documentazione', 'Registro nazionale', 'Attività sportive', 'Agevolazioni fiscali', 'Terzo Settore', 'Pro Loco',];
List data = [];
//
@overrideList<Widget> buildActions(BuildContext context) {return[IconButton(icon: const Icon(Icons.clear), onPressed: () {query = '';},),];}
//
@override
Widget buildLeading(BuildContext context) {return IconButton(icon: const Icon(Icons.arrow_back_ios), onPressed: () {close(context, query);},);}
//
@override
Widget buildResults(BuildContext context) {
List result = suggestions.where((element) => element.toLowerCase().contains(query.toLowerCase())).toList();
return query.isEmpty ? const Center(child: Text("Nessun articolo trovato"),) : ListView.builder(itemCount: result.length, itemBuilder: (context, index) {return ListTile(title: Text(result[index],),);});}
@override
Widget buildSuggestions(BuildContext context) {
List searchedList = suggestions.isEmpty ? data : suggestions.where((element) => element.toLowerCase().contains(query.toLowerCase())).toList();
return ListView.builder(itemCount: searchedList.length, itemBuilder: (context, index) {return ListTile(title: Text(searchedList[index],),);});
}
}