Created
April 4, 2019 15:01
-
-
Save prsnnami/6a5b1178dda4f0c1ab4e6294d497b182 to your computer and use it in GitHub Desktop.
This file contains hidden or 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:demo/profile.dart'; | |
import 'package:demo/second.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Nepal', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: FirstScreen(), | |
routes: { | |
//about | |
//settings | |
"/secondScreen": (context) => SecondScreen(), | |
}, | |
// onUnknownRoute: , | |
onGenerateRoute: (setting) { | |
// profile | |
// detail screen | |
// post detail | |
// | |
var name = setting.name; | |
var splits = name.split("/"); | |
// /profile/21 | |
// ["","profile","21"]; | |
// /detail/31 | |
// ["", "detail","31"]; | |
switch (splits[1]) { | |
case "profile": | |
var profileId = splits[2]; | |
return MaterialPageRoute( | |
builder: (context) => ProfileScreen(profileId)); | |
break; | |
default: | |
} | |
}, | |
); | |
} | |
} | |
class FirstScreen extends StatefulWidget { | |
@override | |
_FirstScreenState createState() => _FirstScreenState(); | |
} | |
class _FirstScreenState extends State<FirstScreen> { | |
int selectedMenu = 0; | |
var _pageController = PageController(); | |
var names = [ | |
"Jon", | |
"Emy", | |
"Test", | |
"Prasanna", | |
"Aawaz", | |
"New Name", | |
"Again New Name", | |
"Feri new name", | |
"Arko pani naya name", | |
"Jon", | |
"Emy", | |
"Test", | |
"Prasanna", | |
"Aawaz", | |
"New Name", | |
"Again New Name", | |
"Feri new name", | |
"Arko pani naya name", | |
"Jon", | |
"Emy", | |
"Test", | |
"Prasanna", | |
"Aawaz", | |
"New Name", | |
"Again New Name", | |
"Feri new name", | |
"Arko pani naya name", | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("First Screen"), | |
), | |
bottomNavigationBar: BottomNavigationBar( | |
currentIndex: selectedMenu, | |
type: BottomNavigationBarType.fixed, | |
onTap: (index) { | |
_pageController.animateToPage( | |
index, | |
duration: Duration(milliseconds: 300), | |
curve: Curves.easeInOut, | |
); | |
setState(() { | |
selectedMenu = index; | |
}); | |
}, | |
items: [ | |
BottomNavigationBarItem( | |
backgroundColor: Colors.red, | |
title: Text("Menu 1"), | |
icon: Icon( | |
Icons.access_alarm, | |
), | |
), | |
BottomNavigationBarItem( | |
backgroundColor: Colors.green, | |
title: Text("Menu 2"), | |
icon: Icon( | |
Icons.access_alarm, | |
), | |
), | |
BottomNavigationBarItem( | |
backgroundColor: Colors.blue, | |
title: Text("Menu 3"), | |
icon: Icon(Icons.access_alarm), | |
), | |
BottomNavigationBarItem( | |
backgroundColor: Colors.pink, | |
title: Text("Menu 4"), | |
icon: Icon(Icons.access_alarm), | |
), | |
], | |
), | |
body: PageView.builder( | |
controller: _pageController, | |
itemBuilder: (context, index) { | |
return Center( | |
child: FlatButton( | |
onPressed: () async { | |
Navigator.pushNamed(context, "/profile/22"); | |
}, | |
child: Text("Menu ${index + 1}"), | |
), | |
); | |
}, | |
itemCount: 4, | |
)); | |
} | |
} |
This file contains hidden or 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'; | |
class ProfileScreen extends StatelessWidget { | |
final String name; | |
ProfileScreen(this.name); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Profile Screen"), | |
), | |
body: Center( | |
child: Text("THis is a profile screen $name"), | |
), | |
); | |
} | |
} |
This file contains hidden or 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'; | |
class SecondScreen extends StatefulWidget { | |
@override | |
_SecondScreenState createState() => _SecondScreenState(); | |
} | |
class _SecondScreenState extends State<SecondScreen> { | |
var name; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Second Screen"), | |
), | |
body: Center( | |
child: Column( | |
children: <Widget>[ | |
TextField( | |
decoration: InputDecoration(hintText: "Name"), | |
onChanged: (value) { | |
setState(() { | |
name = value; | |
}); | |
}, | |
), | |
RaisedButton( | |
child: Text("Done"), | |
onPressed: () { | |
Navigator.pop(context, name); | |
}, | |
) | |
], | |
)), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment