Skip to content

Instantly share code, notes, and snippets.

@rafayali
Created March 16, 2019 10:39
Show Gist options
  • Save rafayali/cdcad84ef330961b4a2caa808def528c to your computer and use it in GitHub Desktop.
Save rafayali/cdcad84ef330961b4a2caa808def528c to your computer and use it in GitHub Desktop.
Flutter UI Challenge - WhatsApp - March 2019
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.green,
),
home: MyHomePage(title: 'WhatsApp'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
final List<Widget> items = List.of({_Messages(), Text("Def")});
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var index = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: CircleAvatar(
backgroundImage: NetworkImage(
'https://pbs.twimg.com/profile_images/1089759246143680513/fCYNB6_9_400x400.jpg',
),
),
),
title: Text(widget.title),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.search,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.settings,
),
onPressed: () {},
),
],
),
body: Center(
child: widget.items[index],
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.phone), title: Text("Phone")),
BottomNavigationBarItem(
icon: Icon(Icons.message), title: Text("Messages")),
BottomNavigationBarItem(
icon: Icon(Icons.group), title: Text("Groups")),
],
currentIndex: index,
onTap: (value) {
setState(() {
debugPrint("index: $value");
index = value;
});
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class _Messages extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.separated(
separatorBuilder: (context, value){
return Container(
height: 2,
color: Colors.grey[200],
);
},
itemCount: 30,
itemBuilder: (context, value){
return ListTile(
onTap: () {},
title: Text("Rafay Ali"),
subtitle: Row(
children: <Widget>[
Icon(Icons.done_all),
SizedBox(width: 4,),
Flexible(child: Text("Hey how about a flutter party next weekend?", maxLines: 1, overflow: TextOverflow.ellipsis,)),
],
),
leading: CircleAvatar(
backgroundImage: NetworkImage(
'https://pbs.twimg.com/profile_images/1089759246143680513/fCYNB6_9_400x400.jpg',
),
),
trailing: Column(
children: <Widget>[
Text(
"Wed",
style: TextStyle(fontWeight: FontWeight.bold),
),
Container(
margin: EdgeInsets.only(top: 4),
padding: EdgeInsets.all(4),
child: Text(
"3",
style: TextStyle(color: Colors.white),
),
color: Colors.green,
)
],
),
);
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment