How can I customize SliverAppBar Flutter? - flutter

Hi Guys I locking for create app bar Like this with SliverAppBar() widget Like this :
And I Tried to make it With SliverAppBar() But The output is like this :
Here is Code :
Scaffold(
drawer: const Drawer(),
body: CustomScrollView(
slivers: [
SliverAppBar(
pinned: true,
elevation: 0,
backgroundColor: Colors.grey.shade200,
title: Text(
"All notes",
style: AppStyle.normalTextStyle
.copyWith(fontWeight: FontWeight.w600),
),
actions: [
IconButton(
onPressed: () => Get.to(() => SearchBar(notes: notes)),
icon: const Icon(Icons.search)),
IconButton(
onPressed: () {},
icon: const Icon(Icons.more_vert_outlined))
],
expandedHeight: 200,
flexibleSpace: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 80),
Text(
"All notes",
style: AppStyle.largeTextStyle
.copyWith(fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
Text(
"${notes.length} notes",
style: AppStyle.smallTextStyle
.copyWith(fontWeight: FontWeight.w400),
),
],
),
),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: GridView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
primary: false,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
mainAxisExtent: 170,
crossAxisCount: 2,
),
itemCount: notes.length,
itemBuilder: (context, index) {
final note = notes[index];
return GestureDetector(
onTap: () =>
Get.to(() => DetailsScreen(id: note.id)),
child: BaseContainer(note: note));
},
)),
),
],
),
floatingActionButton: SizedBox(
height: 65,
width: 65,
child: FloatingActionButton(
tooltip: 'Add note',
child: const Icon(
Icons.add,
size: 30,
),
onPressed: () => Get.to(() => const AddScreen()),
),
),
);
So how can I reverse SliverAppBar() when it's scrolling just like a first video ?
and second question is how can I remove that All notes text when it's scrolling and replace it with Large one just like first Video ..
if it possible to create that appBar like the first video (Samsung notes appBar) except SliverAppBar() please let me know .

Please refer to the below code
class _AnimatedAppBarState extends State<AnimatedAppBar>
with TickerProviderStateMixin {
final TextEditingController stateController = TextEditingController();
final FocusNode stateFocus = FocusNode();
var animation;
var controller;
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: NestedScrollView(
headerSliverBuilder:
(BuildContext context, bool innnerBoxIsScrolled) {
if (innnerBoxIsScrolled) {
/* Animation */
controller = AnimationController(
vsync: this,
duration: Duration(
seconds: 1,
),
);
animation = Tween(
begin: 0.0,
end: 1.0,
).animate(controller);
/* Animation */
controller.forward();
}
return <Widget>[
SliverAppBar(
expandedHeight: 120.0,
floating: false,
pinned: true,
backgroundColor: Colors.blueGrey,
automaticallyImplyLeading: false,
titleSpacing: 0.0,
toolbarHeight:
(innnerBoxIsScrolled != null && innnerBoxIsScrolled == true)
? 60.0
: 160.0,
centerTitle: false,
elevation: 0.0,
leadingWidth: 0.0,
title: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (innnerBoxIsScrolled != null &&
innnerBoxIsScrolled == true)
FadeTransition(
opacity: animation,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 5.0,
),
Row(
children: [
SizedBox(
width: 5.0,
),
Icon(
Icons.menu,
color: Colors.black,
),
SizedBox(
width: 10.0,
),
Text(
"All Notes",
style: TextStyle(
color: Colors.black,
),
),
Spacer(),
Icon(
Icons.search,
color: Colors.black,
),
SizedBox(
width: 10.0,
),
Icon(
Icons.more_vert,
color: Colors.black,
),
],
),
],
),
),
],
),
flexibleSpace: FlexibleSpaceBar(
background: Container(
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 30.0,
),
Text(
"All Notes",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24.0,
),
),
Text(
"2 Notes",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24.0,
),
),
Spacer(),
Row(
children: [
SizedBox(
width: 5.0,
),
Icon(
Icons.menu,
color: Colors.black,
),
Spacer(),
Icon(
Icons.search,
color: Colors.black,
),
SizedBox(
width: 10.0,
),
Icon(
Icons.more_vert,
color: Colors.black,
),
],
),
SizedBox(
height: 10.0,
)
],
),
),
),
),
];
},
body: Builder(
builder: (BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
ListView.builder(
itemCount: 100,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(4.0),
child: Text("Index value: $index"),
);
},
)
],
),
);
},
),
),
),
);
}
}

import "package:flutter/material.dart";
void main()=>runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: "SliverAppBar",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
),
home: Home(),
);
}
}
class Home extends StatefulWidget {
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
bool x=true;
bool y=true;
bool z=true;
void xxx(){
setState(() {
x=!x;
});
}
void yyy(){
setState(() {
y=!y;
});
}
void zzz(){
setState(() {
z=!z;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
centerTitle: z,
pinned: x,
floating: y,
expandedHeight: 150.0,
flexibleSpace: FlexibleSpaceBar(
title: Text("CodeCave"),
),
actions: <Widget>[
IconButton(icon: Icon(Icons.fiber_pin),tooltip: "Pinned",onPressed: xxx,),
IconButton(icon: Icon(Icons.flare),tooltip: "Floating",onPressed: yyy,),
IconButton(icon: Icon(Icons.center_focus_strong),tooltip: "Center Text",onPressed: zzz,),
],
),
SliverFillRemaining(
child: Center(
child: Text("DEMO"),
),
),
],
),
);
}
}

Related

how to create add minus button on my product in flutter?

May I know how to create a function that displays the value and have the button remove and add to the product list? I already create an icon button for remove and add to the screen but I do not have any clues on how to use the button.
GUI on application:
my aim is to have this kind of button:
my full code for this GUI:
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'CartList.dart';
import 'bottom_navi_iconW.dart';
import 'globals.dart' as globals;
class SarapanPagi extends StatefulWidget {
final List list;
final int index;
final String category;
SarapanPagi({this.index,this.list,this.category});
#override
_SarapanPagiState createState() => _SarapanPagiState();
}
class _SarapanPagiState extends State<SarapanPagi> {
Future<List> getData() async{
var url = 'http://10.0.2.2/foodsystem/breakfastlist.php';
var data = {
'product_type': globals.jenisCategory,
'product_owner': widget.list[widget.index]['restaurant_id'],
};
var response = await http.post(url, body: json.encode(data));
//final response= await http.get("http://10.0.2.2/foodsystem/getdata.php");
return json.decode(response.body);}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.black),
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
//Text("Restaurant's Owner Page"),
Text(widget.list[widget.index]['restaurant_name'], textAlign: TextAlign.center, style: TextStyle(fontWeight: FontWeight.w700), ),
],
),
centerTitle: false,
//automaticallyImplyLeading: false,
),
body:
Padding(
padding: const EdgeInsets.only(bottom: 0, left: 5, right: 5),
child: Column(
children: [
/*FloatingActionButton(
onPressed: (){
return showDialog(
context: context,
builder: (context){
return AlertDialog(
content: Text(
globals.jenisCategory
),
);
},
);
},
),*/
//SizedBox(height: 30,),
Container(
//decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 4), borderRadius: BorderRadius.circular(15)),
height: 627,
child: FutureBuilder<List>(
future: getData(),
builder: (context, snapshot){
if(snapshot.hasError) print(snapshot.error);
return snapshot.hasData ?
ItemList(list: snapshot.data,) :
Center(child: CircularProgressIndicator(),);
},
),
),
],
),
),
bottomNavigationBar:
Container(
height: 70,
color: Colors.red,
child: BottomNavIcon(
onTap: (){
Navigator.of(context).push(new MaterialPageRoute(
builder: (BuildContext context)=> new CartListItem()),);
},
image: "troli.png",
name: "CART",
),
),
);
}
}
class ItemList extends StatelessWidget {
final List list;
ItemList({this.list});
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
//color: Colors.red.shade100,
height: 627,
child: ListView.builder(
itemCount: list==null ? 0 : list.length,
itemBuilder: (context, i){
return new Container(
//decoration: BoxDecoration(border: Border.all(color: Colors.blue, width: 4), borderRadius: BorderRadius.circular(15)),
height: 250,
child: new GestureDetector(
onTap: (){},
child: new Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [
Padding(
padding: const EdgeInsets.only(bottom : 5.0),
child: Text(list[i]["product_name"], textAlign: TextAlign.center, style: TextStyle(fontSize: 23, fontWeight: FontWeight.bold),),
),
Row(
children: [
//Text(list[i]["product_name"], textAlign: TextAlign.center, style: TextStyle(fontSize: 30),),
Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"menulist/${list[i]['image']}",
width: 150,
height: 150,
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0, bottom: 0),
child:
Column(
children: [
//Text(list[i]["product_name"], textAlign: TextAlign.center, style: TextStyle(fontSize: 30),),
Text("Price RM : ${list[i]["product_price"]}", textAlign: TextAlign.center, style: TextStyle(fontSize: 25),),
Row(
children: [
IconButton(
icon: Icon(Icons.remove),
onPressed: (){},
iconSize: 15,
),
IconButton(
icon: Icon(Icons.add),
onPressed: (){},
iconSize: 15,
),
],
),
RaisedButton(
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(40.0)),
color: Colors.red.shade300,
child: Text("Add to Cart", style: TextStyle(fontWeight: FontWeight.bold),),
onPressed: (){},
)
],
),
),
],
),
],
),
/*ListTile(
title: Text(list[i]["product_name"], textAlign: TextAlign.center, style: TextStyle(fontSize: 30),),
leading:
Image.asset(
"images/${list[i]['image']}",
width: 100,
height: 100,
),
subtitle: Text("Price RM : ${list[i]["product_price"]}", textAlign: TextAlign.center, style: TextStyle(fontSize: 25),),
),*/
],
),
),
),
);
},
),
),
);
}
}
First of all you need to change it to StatefulWidget, since the UI interaction is rendered (changed price). Then something like
onPressed: () => setState(() => list[i]["product_price"] += unitprice),
will do

How to create a vertical scrolling menu effect in Flutter

this question is an improvement for this question. In this case, I would like to reproduce the vertical menu the you can see on the left side of this we base. If you click the link relative to the example on the left you see a number of menu. For instance, clicking on Base you are going to see a vertical menu appearing and disappearing. I would like to know how to reproduce it as well. An example code would be really appreciated.
Thanks all
You can achieve this by simply using a StatefulWidget & managing the hide/show functionality using a boolean value.
Here is the updated code:
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatefulWidget {
#override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget>
with SingleTickerProviderStateMixin {
final colors = <Color>[Colors.indigo, Colors.blue, Colors.orange, Colors.red];
double _size = 250.0;
bool _large = true;
void _updateSize() {
setState(() {
_size = _large ? 250.0 : 0.0;
_large = !_large;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
AnimatedSize(
curve: Curves.easeIn,
vsync: this,
duration: Duration(seconds: 1),
child: LeftDrawer(size: _size)),
Expanded(
flex: 4,
child: Container(
child: Column(
children: [
Container(
color: Colors.white,
padding: const EdgeInsets.all(8),
child: Row(
children: [
IconButton(
icon: Icon(Icons.menu, color: Colors.black87),
onPressed: () {
_updateSize();
},
),
FlatButton(
child: Text(
'Dashboard',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
FlatButton(
child: Text(
'User',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
FlatButton(
child: Text(
'Settings',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
const Spacer(),
IconButton(
icon: Icon(Icons.brightness_3, color: Colors.black87),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.notification_important,
color: Colors.black87),
onPressed: () {},
),
CircleAvatar(),
],
),
),
Container(
height: 1,
color: Colors.black12,
),
Card(
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
color: Colors.white,
padding: const EdgeInsets.all(20),
child: Row(
children: [
Text(
'Home / Admin / Dashboard',
style: const TextStyle(color: Colors.black),
),
],
),
),
),
Expanded(
child: ListView(
children: [
Row(
children: [
_container(0),
_container(1),
_container(2),
_container(3),
],
),
Container(
height: 400,
color: Color(0xFFE7E7E7),
padding: const EdgeInsets.all(16),
child: Card(
color: Colors.white,
child: Container(
padding: const EdgeInsets.all(16),
child: Text(
'Traffic',
style: const TextStyle(color: Colors.black87),
),
),
),
),
],
),
),
],
),
),
),
],
),
);
}
Widget _container(int index) {
return Expanded(
child: Container(
padding: const EdgeInsets.all(20),
color: Color(0xFFE7E7E7),
child: Card(
color: Color(0xFFE7E7E7),
child: Container(
color: colors[index],
width: 250,
height: 140,
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
'9.823',
style: TextStyle(fontSize: 24),
)),
Icon(Icons.more_vert),
],
),
Text('Members online')
],
),
),
),
),
);
}
}
class LeftDrawer extends StatefulWidget {
LeftDrawer({
Key key,
this.size,
}) : super(key: key);
final double size;
#override
_LeftDrawerState createState() => _LeftDrawerState();
}
class _LeftDrawerState extends State<LeftDrawer> {
bool dropdownVisible = false;
#override
Widget build(BuildContext context) {
return Expanded(
flex: 1,
child: Container(
width: widget.size,
color: const Color(0xFF2C3C56),
child: ListView(
children: [
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(16),
color: Color(0xFF223047),
child: Text('CORE UI'),
),
_tile('Dashboard'),
Container(
padding: const EdgeInsets.only(left: 10),
margin: const EdgeInsets.only(top: 30),
child: Text('THEME',
style: TextStyle(
color: Colors.white54,
))),
_tile('Colors'),
_tile('Typography'),
_tileDropdown('Base'),
_tile('Buttons'),
],
),
),
);
}
Widget _tile(String label) {
return ListTile(
title: Text(label),
onTap: () {},
);
}
Widget _option(String label) {
return ListTile(
tileColor: Color(0xFF223047),
contentPadding: const EdgeInsets.only(left: 40),
title: Text(label),
onTap: () {},
);
}
Widget _tileDropdown(String label) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: Text(label),
onTap: () {
setState(() {
dropdownVisible = !dropdownVisible;
});
},
trailing: dropdownVisible
? Icon(Icons.arrow_drop_up)
: Icon(Icons.chevron_left),
),
Visibility(
visible: dropdownVisible,
child: _option('Breadcrumbs'),
),
Visibility(
visible: dropdownVisible,
child: _option('Cloud'),
),
Visibility(
visible: dropdownVisible,
child: _option('Carousel'),
),
Visibility(
visible: dropdownVisible,
child: _option('Collapse'),
),
],
);
}
}

How to dynamically sort by date in flutter?

I am working on a to do list app on flutter and I will like to sort the uploaded tasks by date(new ones appear first). for doing this I think a key should be givin to each of the uploaded items in the to do list and this key should include a Date. In react native for doing this I added a function to the data in a flatlist which sorted by date but since I am new to flutter I dont know how can that be done. Any Idea helps :)
main.dart
List<String> _toDoItems = []; //this is the array in which the uploaded tasks are stored, btw Im not using any database.
TextEditingController _controller = TextEditingController();
void _addToDoItem(String task) {
if(task.length > 0) {
setState(() {
_toDoItems.add(task);
});
}
}
void _removeTodoItem(int index) {
setState(() => _toDoItems.removeAt(index));
}
Widget _buildToDoItem(String toDoText, int index) {
return SizedBox(
child: Container(
height: 58,
margin: EdgeInsets.only(left: 22.0, right: 22.0, bottom: 12,),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.red),
borderRadius: BorderRadius.all(Radius.circular(18)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children:[
Expanded(
child: ListTile(
title: Text(
toDoText,
style: TextStyle(fontSize: 18),
),
onTap: () => _removeTodoItem(index),
),
),
FlatButton(
child: Text('Delete', style: TextStyle(color: Colors.red, fontSize: 16.5),),
onPressed: () => _removeTodoItem(index),
),
],
),
),
);
}
Widget _buildToDoList() {
return Expanded(
child: ListView.builder(
itemBuilder: (context, index) {
if (index < _toDoItems.length) {
return _buildToDoItem(_toDoItems[index], index);
}
},
),
);
}
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(50),
child: AppBar(
centerTitle: true,
backgroundColor: Colors.red,
title: Text('To Do List', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold,),),
)
),
backgroundColor: Colors.white,
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 60,
margin: EdgeInsets.all(22),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 10,
child: Container(
height: double.infinity,
child: TextField(
controller: _controller,
autofocus: true,
onSubmitted: (val) {
_addToDoItem(val);
_controller.clear();
},
style: TextStyle(fontSize: 18,),
),
),
),
Expanded(
flex: 4,
child: Container(
height: double.infinity,
margin: EdgeInsets.only(left: 12),
child: RaisedButton(
textColor: Colors.white,
color: Colors.red,
child: Text('ADD', style: TextStyle(fontSize: 18)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12)),
),
onPressed: () {
_addToDoItem(_controller.text);
_controller.clear();
FocusScope.of(context).requestFocus(FocusNode());
},
),
),
),
],
),
),
_buildToDoList()
]
),
),
);
}
You need to use the sort() method of List, also you need to be able to stock in a way or another the time of creation of your task.
I've made an example with the code you've posted. Using it your last created element will always be the first of the list.
import 'package:flutter/material.dart';
class ToDoElement {
final String task;
final DateTime timeOfCreation;
ToDoElement(this.task, this.timeOfCreation);
}
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
createState() => _MyAppState();
}
class _MyAppState extends State {
TextEditingController _controller = TextEditingController();
List<ToDoElement> _toDoItems = [];
void _removeTodoItem(int index) {
setState(() => _toDoItems.removeAt(index));
}
void _addToDoItem(String task) {
if (task.isNotEmpty) {
setState(() => _toDoItems.add(ToDoElement(task, DateTime.now())));
}
}
Widget _buildToDoItem(String toDoText, int index) {
return SizedBox(
child: Container(
height: 58,
margin: EdgeInsets.only(left: 22, right: 22, bottom: 12),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.red),
borderRadius: BorderRadius.all(Radius.circular(18)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: ListTile(
title: Text(
toDoText,
style: TextStyle(fontSize: 18),
),
onTap: () => _removeTodoItem(index),
),
),
FlatButton(
child: Text(
'Delete',
style: TextStyle(color: Colors.red, fontSize: 16.5),
),
onPressed: () => _removeTodoItem(index),
),
],
),
),
);
}
int compareElement(ToDoElement a, ToDoElement b) =>
a.timeOfCreation.isAfter(b.timeOfCreation) ? -1 : 1;
Widget _buildToDoList() {
_toDoItems.sort(compareElement);
return Expanded(
child: ListView.builder(
itemCount: _toDoItems.length,
itemBuilder: (context, index) {
return _buildToDoItem(_toDoItems[index].task, index);
},
),
);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(50),
child: AppBar(
centerTitle: true,
backgroundColor: Colors.red,
title: Text(
'To Do List',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
)),
backgroundColor: Colors.white,
body: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
Container(
height: 60,
margin: EdgeInsets.all(22),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 10,
child: Container(
height: double.infinity,
child: TextField(
controller: _controller,
autofocus: true,
onSubmitted: (val) {
_addToDoItem(val);
_controller.clear();
},
style: TextStyle(
fontSize: 18,
),
),
),
),
Expanded(
flex: 4,
child: Container(
height: double.infinity,
margin: EdgeInsets.only(left: 12),
child: RaisedButton(
textColor: Colors.white,
color: Colors.red,
child: Text('ADD', style: TextStyle(fontSize: 18)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12)),
),
onPressed: () {
_addToDoItem(_controller.text);
_controller.clear();
FocusScope.of(context).requestFocus(FocusNode());
},
),
),
),
],
),
),
_buildToDoList()
]),
),
);
}
}

Sliver navigation flutter for Spotify like appearance

I was listening to music on Spotify, and started wondering how to get the exact animation shown in the Artist page.
It includes sliver navigation, but also text on top of the artist image (maybe a simple stack would work)
Also there's a floating action widget (shuffle play) and, my favourite, the artist image ZOOMS back when scrolled up!
I want to recreate it on Flutter.
Can anyone help me?
I don't use Spotify.
but I hope It could give good beginning.
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
themeMode: ThemeMode.dark,
darkTheme: ThemeData.dark(),
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: MyHomePage(),
),
),
);
}
}
double _appTopBarHeight = 60;
String artistName = 'Dennis Lloyd';
class MyHomePage extends StatelessWidget {
const MyHomePage({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return CustomScrollView(
slivers: [
SliverPersistentHeader(
delegate: MyDelegate(),
floating: true,
pinned: true,
),
SliverList(
delegate: SliverChildBuilderDelegate(
(_, index) => Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(index.toString()),
SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Title'),
Text('Subtitle'),
],
),
),
SizedBox(width: 10),
Icon(
Icons.more_vert,
color: Colors.white,
),
],
),
),
),
childCount: 100,
),
),
],
);
}
}
class MyDelegate extends SliverPersistentHeaderDelegate {
#override
Widget build(_, double shrinkOffset, bool overlapsContent) {
var shrinkPercentage =
min(1, shrinkOffset / (maxExtent - minExtent)).toDouble();
return Stack(
overflow: Overflow.clip,
fit: StackFit.expand,
children: [
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
height: _appTopBarHeight,
color: Colors.black,
),
),
Column(
children: [
Flexible(
flex: 1,
child: Stack(
children: [
Container(
color: Colors.black,
),
Opacity(
opacity: 1 - shrinkPercentage,
child: Container(
height: 900,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fitWidth,
alignment: FractionalOffset.topCenter,
image: NetworkImage(
'https://66.media.tumblr.com/c063f0b98040e8ec4b07547263b8aa15/tumblr_inline_ppignaTjX21s9on4d_540.jpg'),
)),
),
),
],
),
),
Container(
height: 50,
)
],
),
Stack(
overflow: Overflow.clip,
fit: StackFit.expand,
children: [
Positioned(
top: 0,
left: 0,
right: 0,
child: Column(
children: [
Container(
height: _appTopBarHeight,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(
Icons.arrow_back,
color: Colors.white,
),
Flexible(
child: Opacity(
opacity: shrinkPercentage,
child: Text(
artistName,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
),
Icon(
Icons.more_vert,
color: Colors.white,
),
],
),
),
),
Opacity(
opacity: max(1 - shrinkPercentage * 6, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
SizedBox(height: 200),
Text(
artistName,
style: TextStyle(
fontSize: 48,
fontWeight: FontWeight.bold,
),
),
Text(
'Subtitle',
style: TextStyle(color: Colors.white),
),
],
),
)
],
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Center(
child: RaisedButton(
color: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(),
),
onPressed: () {},
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 30, vertical: 5),
child: Text(
'SHUFFLE PLAY',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
),
),
),
)
],
),
],
);
}
#override
double get maxExtent => 400;
#override
double get minExtent => 110;
#override
bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => true;
}

Flutter : Image Lost in SliverAppBar

I'm Working with SliverAppBar.
Previous I have 2 Page Let's Say (Search,and Detail) ,
In Detail Page,I have problem When i Scroll Down and make Image not visible after that I'm press button Back , My Image lost in Search Page. But if i Scroll down and then little Scroll Up to make Image visible after that i press Back button , My image not lost and still stay there.
It's may be confusing, but you can see the GIF for more detail.
Can you help Me with this ?
Thank's
It's Detail.dart :
import 'package:flutter/material.dart';
import 'package:flutter_news/model/Berita_model.dart';
import 'package:flutter_news/widget/Widget_builder.dart';
class WartawanDetail extends StatefulWidget {
final int idWartawan;
final String gambarWartawan;
final String namaWartawan;
WartawanDetail({this.idWartawan, this.gambarWartawan, this.namaWartawan});
#override
_WartawanDetailState createState() => _WartawanDetailState();
}
class _WartawanDetailState extends State<WartawanDetail> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
floating: true,
pinned: false,
leading: IconButton(
icon: Icon(Icons.arrow_left),
onPressed: () => Navigator.pop(context),
),
expandedHeight: 300.0,
centerTitle: true,
flexibleSpace: FlexibleSpaceBar(
background: Hero(
tag: widget.idWartawan,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.gambarWartawan),
fit: BoxFit.cover),
),
child: Stack(
children: <Widget>[
Positioned(
bottom: 10,
left: 10,
child: Material(
color: Colors.transparent,
child: Chip(
backgroundColor: Colors.blue,
labelStyle: TextStyle(color: Colors.white),
label: Text(widget.namaWartawan),
),
),
),
Positioned(
bottom: 10,
right: 10,
child: Material(
color: Colors.transparent,
child: Chip(
backgroundColor: Colors.blue,
labelStyle: TextStyle(color: Colors.white),
label: Text("2 Berita"),
),
),
),
],
),
),
),
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.more_horiz),
onPressed: () => "",
),
],
),
SliverFixedExtentList(
itemExtent: MediaQuery.of(context).size.height,
delegate: SliverChildListDelegate(
[
Container(
padding: EdgeInsets.all(8),
child: ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: beritas.length,
itemBuilder: newsBuilderHome),
),
],
),
)
],
),
);
}
}
It's My Search.dart
Widget wartawanBuilderSearch(BuildContext context, int index) {
ThemeData localTheme = Theme.of(context);
return Container(
margin: EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
child: Hero(
tag: wartawans[index].idWartawan,
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () => Navigator.push(
context,
PageTransition(
type: PageTransitionType.downToUp,
child: WartawanDetail(
idWartawan:wartawans[index].idWartawan,
gambarWartawan: wartawans[index].gambarWartawan,
namaWartawan: wartawans[index].namaWartawan,
),
),
),
child: CircleAvatar(
backgroundColor: Colors.red,
radius: 50,
backgroundImage:
AssetImage(wartawans[index].gambarWartawan),
),
),
),
),
),
),
Container(
child: Align(
alignment: Alignment.bottomLeft,
child: Text(
wartawans[index].namaWartawan,
style: localTheme.textTheme.caption
.copyWith(fontSize: 14, fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
),
),
)
],
),
);
}