Last active
June 23, 2019 09:31
-
-
Save benznest/97f611594f757f41e216fc8bddc1c0f1 to your computer and use it in GitHub Desktop.
Zealtech
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
import 'package:flutter/material.dart'; | |
import 'package:flutter_app_3/email.dart'; | |
import 'package:flutter_animation_progress_bar/flutter_animation_progress_bar.dart'; | |
class DetailScreen extends StatelessWidget { | |
final Email email; | |
final GlobalKey<ScaffoldState> keyScaffold = GlobalKey(); | |
DetailScreen({@required this.email}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
key: keyScaffold, | |
appBar: AppBar( | |
elevation: 0, | |
backgroundColor: Colors.red[300], | |
actions: <Widget>[ | |
IconButton(icon: Icon(Icons.share), onPressed: () { | |
shareEmail(); | |
}), | |
IconButton(icon: Icon(Icons.delete), onPressed: () { | |
deleteEmail(context); | |
}) | |
], | |
title: Text("My Email"),), | |
body: Container( | |
color: Colors.grey[300], | |
child: ListView(children: <Widget>[ | |
Container( | |
margin: EdgeInsets.all(16), | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(8), | |
color: Colors.white), | |
padding: EdgeInsets.all(16), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
Text("${email.title}", style: TextStyle(fontSize: 28),), | |
Text("${email.content}", style: TextStyle(fontSize: 20),), | |
GestureDetector( | |
onTap: () { | |
showImage(context, "assets/images/black_mirror.jpg"); | |
}, | |
child: Image.asset("assets/images/black_mirror.jpg")), | |
FAProgressBar( | |
currentValue: 80, | |
displayText: '%', | |
) | |
], | |
)) | |
],),)); | |
} | |
void shareEmail() { | |
keyScaffold.currentState.showSnackBar(SnackBar( | |
content: Text("Share !!"), | |
backgroundColor: Colors.red[300],)); | |
} | |
void deleteEmail(context) { | |
showDialog(context: context, | |
builder: (context) { | |
return AlertDialog( | |
title: Text("Are you sure remove"), | |
actions: <Widget>[ | |
FlatButton(child: Text("Delete"), onPressed: () {},), | |
FlatButton(child: Text("Cancel"), onPressed: () {},), | |
]); | |
}); | |
} | |
void showImage(context, String pathImage) { | |
showDialog(context: context, | |
builder: (context) { | |
return GestureDetector(child: Container(child: Image.asset(pathImage)), | |
onTap: () { | |
Navigator.pop(context); | |
},); | |
}); | |
} | |
} |
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
class Email{ | |
String title; | |
String content; | |
String date; | |
bool read; | |
Email({this.title="", this.content="", this.date="",this.read = false}); | |
} |
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
import 'package:flutter/material.dart'; | |
import 'package:flutter_app_3/second_screen.dart'; | |
void main() => | |
runApp(MaterialApp( | |
home: MyApp(), | |
)); | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
int counter; | |
PageController pageController = PageController(); | |
int currentPage; | |
@override | |
void initState() { | |
currentPage = 0; | |
counter = 0; | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text("My App"), | |
centerTitle: true, | |
backgroundColor: Colors.red[300], | |
actions: <Widget>[ | |
IconButton(icon: Icon(Icons.search), onPressed: () { | |
// | |
}), | |
IconButton(icon: Icon(Icons.list), onPressed: () { | |
Navigator.push(context, MaterialPageRoute(builder: (context) { | |
return SecondScreen(); | |
})); | |
}), | |
]), | |
drawer: Drawer(child: ListView(children: <Widget>[ | |
Container(constraints: BoxConstraints.expand(height: 150), | |
decoration: BoxDecoration( | |
gradient: LinearGradient(colors: [Colors.red[300], Colors.purple[200]], | |
begin: Alignment.topLeft, | |
end: Alignment.bottomRight))), | |
ListTile(leading: Icon(Icons.favorite, size: 36,), | |
title: Text("Add 100"), subtitle: Text("Add value 100 to counter."), | |
onTap: () => incrementCounter(value: 100) | |
), | |
ListTile(leading: Icon(Icons.refresh, size: 36,), | |
title: Text("Reset"), subtitle: Text("Reset value of counter."), | |
onTap: () => resetCounter() | |
), | |
],),), | |
body: PageView(controller: pageController, | |
children: <Widget>[ | |
Container(constraints: BoxConstraints.expand(), | |
color: Colors.purple[100], | |
child: Center(child: | |
Container( | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(8), | |
gradient: LinearGradient(colors: [Colors.red[300], Colors.purple[200]], | |
begin: Alignment.topLeft, | |
end: Alignment.bottomRight)), | |
padding: EdgeInsets.all(16), | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
Text("My counter", style: TextStyle(fontSize: 28, color: Colors.white)), | |
Text("$counter", style: TextStyle(fontSize: 48, color: Colors.white)), | |
], | |
)))), | |
Container() | |
]), | |
floatingActionButton: FloatingActionButton(backgroundColor: Colors.red, child: Icon(Icons.add) | |
, onPressed: () { | |
incrementCounter(); | |
}), | |
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, | |
bottomNavigationBar: BottomAppBar(shape: CircularNotchedRectangle(), | |
child: Row( | |
children: <Widget>[ | |
Spacer(), | |
Container(margin: EdgeInsets.symmetric(vertical: 8),padding: EdgeInsets.all(6), child: Text("Home", style: TextStyle(color: Colors.white),), | |
decoration: BoxDecoration(color: Colors.red[300], borderRadius: BorderRadius.circular(8))), | |
Spacer(), | |
Spacer(), | |
Container(margin: EdgeInsets.symmetric(vertical: 8),padding: EdgeInsets.all(6), child: Text("Favorite")), | |
Spacer(), | |
]),), | |
// BottomNavigationBar(currentIndex: currentPage, | |
// items: [ | |
// BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("Home")), | |
// BottomNavigationBarItem(icon: Icon(Icons.favorite), title: Text("Favorite")), | |
// ], onTap: (index) { | |
// setState(() { | |
// currentPage = index; | |
// pageController.animateToPage(index, duration: Duration(seconds: 1), curve: Curves.easeInSine); | |
// }); | |
// }) | |
); | |
} | |
void incrementCounter({int value = 1}) { | |
setState(() { | |
counter += value; | |
}); | |
} | |
void resetCounter() { | |
setState(() { | |
counter = 0; | |
}); | |
} | |
} |
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
import 'package:flutter/material.dart'; | |
import 'package:flutter_app_3/detail_screen.dart'; | |
import 'package:flutter_app_3/email.dart'; | |
class SecondScreen extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() { | |
return SecondScreenState(); | |
} | |
} | |
class SecondScreenState extends State<SecondScreen> { | |
TextEditingController textFieldSearchController = TextEditingController(); | |
List<Email> listEmailAll = [ | |
Email(title: "Hello", content: "How are you", date: "23 Jun 2019", read: true), | |
Email(title: "Android Open Source", content: "Google IO 2019"), | |
Email(title: "Cafe Amazon", content: "Free 1 cup", read: true), | |
Email(title: "Apple Macbook Pro 2019, on Apple Store", content: "New today for you"), | |
]; | |
List<Email> listEmailSearch = List(); | |
@override | |
void initState() { | |
listEmailSearch = List.of(listEmailAll); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
elevation: 0, | |
backgroundColor: Colors.red[300], | |
title: Text("My List"),), | |
body: Column( | |
children: <Widget>[ | |
Container( | |
color: Colors.red[300], | |
padding: EdgeInsets.only(right: 16, left: 16, bottom: 8), | |
child: Row( | |
children: <Widget>[ | |
Expanded(child: | |
Container( | |
padding: EdgeInsets.all(8), | |
decoration: BoxDecoration( | |
color: Colors.white, | |
borderRadius: BorderRadius.circular(8)), | |
child: Row( | |
children: <Widget>[ | |
Icon(Icons.search, color: Colors.grey[400],), | |
Expanded( | |
child: TextField( | |
controller: textFieldSearchController, | |
decoration: InputDecoration.collapsed(hintText: "Search"), | |
onChanged: (text) { | |
searchEmail(text.toLowerCase()); | |
})), | |
], | |
))), | |
SizedBox(width: 8,), | |
Text("${listEmailSearch.length} items", style: TextStyle(fontSize: 18, color: Colors.white)) | |
], | |
),), | |
Expanded(child: Container(color: Colors.grey[300], | |
child: ListView.builder( | |
padding: EdgeInsets.symmetric(vertical: 16), | |
itemCount: listEmailSearch.length, | |
itemBuilder: (context, index) => buildEmailItem(context, listEmailSearch[index]) | |
))), | |
], | |
)); | |
} | |
Widget buildEmailItem(context, Email email) { | |
return GestureDetector( | |
onTap: () { | |
Navigator.push(context, MaterialPageRoute(builder: (context) => DetailScreen(email: email))); | |
}, | |
child: Opacity(opacity: email.read ? 1.0 : 0.4, | |
child: Container( | |
decoration: BoxDecoration( | |
color: Colors.white, | |
borderRadius: BorderRadius.circular(8)), | |
padding: EdgeInsets.all(16), | |
margin: EdgeInsets.symmetric(vertical: 4, horizontal: 16), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.end, | |
children: <Widget>[ | |
Row( | |
mainAxisSize: MainAxisSize.max, | |
children: <Widget>[ | |
CircleAvatar(radius: 36, | |
backgroundColor: Colors.red[300], | |
child: Icon(Icons.email, size: 36,)), | |
SizedBox(width: 8,), | |
Expanded(child: | |
Column( | |
mainAxisSize: MainAxisSize.min, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
Text("${email.title}", style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold,)), | |
Text("${email.content}", style: TextStyle(fontSize: 18),), | |
], | |
)), | |
], | |
), | |
Text("${email.date}", style: TextStyle(fontSize: 14),), | |
], | |
)))); | |
} | |
void searchEmail(String text) { | |
setState(() { | |
listEmailSearch = listEmailAll.where((email) => | |
email.title.toLowerCase().contains(text) || email.content.toLowerCase().contains(text) | |
).toList(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment