Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 80e2815

Browse files
author
Madda, Shylendra
committed
Add samples list, bottom nav, output and code
1 parent 0391d9e commit 80e2815

File tree

10 files changed

+602
-26
lines changed

10 files changed

+602
-26
lines changed

‎assets/images/flutter_icon.png‎

45.2 KB
Loading[フレーム]

‎assets/images/flutter_logo.png‎

12.3 KB
Loading[フレーム]

‎lib/code.dart‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:flutter/material.dart';
2+
3+
import 'home.dart';
4+
5+
class CodeWidget extends StatelessWidget {
6+
final Sample sample;
7+
8+
CodeWidget({Key key, @required this.sample}) : super(key: key);
9+
10+
@override
11+
Widget build(BuildContext context) {
12+
return Container(
13+
child: Center(
14+
child: Padding(
15+
padding: const EdgeInsets.all(20),
16+
child: SelectableText(sample.sourceCode,
17+
style: TextStyle(color: Colors.white, fontStyle: FontStyle.italic)),
18+
)));
19+
}
20+
}

‎lib/home.dart‎

Lines changed: 252 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,262 @@ import 'package:fluttersamples/sample.dart';
33

44
class HomeScreen extends StatefulWidget {
55
@override
6-
_HomeScreenState createState() => new _HomeScreenState();
6+
HomeScreenState createState() => new HomeScreenState();
77
}
88

9-
10-
class _HomeScreenState extends State<HomeScreen> {
9+
class HomeScreenState extends State<HomeScreen> {
1110
List<Sample> sampleEntries = List();
1211

1312
@override
1413
Widget build(BuildContext context) {
14+
sampleEntries.add(new Sample(1, "Splash Screen", """"
15+
16+
import 'dart:async';
17+
18+
import 'package:flutter/material.dart';
19+
20+
import 'home.dart';
21+
22+
void main() {
23+
runApp(MaterialApp(
24+
home: SplashScreen(),
25+
routes: <String, WidgetBuilder>{
26+
'/HomeScreen': (BuildContext context) => HomeScreen()
27+
},
28+
));
29+
}
30+
31+
class SplashScreen extends StatefulWidget {
32+
@override
33+
SplashScreenState createState() => SplashScreenState();
34+
}
35+
36+
class SplashScreenState extends State<SplashScreen> {
37+
@override
38+
void initState() {
39+
super.initState();
40+
startTime();
41+
}
1542
16-
sampleEntries.add(new Sample(1, "Splash Screen 1", "Description1"));
17-
sampleEntries.add(new Sample(2, "Splash Screen 2", "Description2"));
18-
sampleEntries.add(new Sample(3, "Splash Screen 3", "Description3"));
43+
startTime() async {
44+
var duration = Duration(seconds: 2);
45+
return Timer(duration, navigationPage);
46+
}
47+
48+
void navigationPage() {
49+
Navigator.of(context).pushReplacementNamed('/HomeScreen');
50+
}
51+
52+
@override
53+
Widget build(BuildContext context) {
54+
return Scaffold(
55+
body: Center(
56+
child: Image.asset('assets/images/flutter_icon.png',
57+
width: 200, height: 200, fit: BoxFit.fill),
58+
),
59+
);
60+
}
61+
}
62+
63+
"""));
64+
sampleEntries.add(new Sample(2, "Login Screen", """
65+
66+
import 'package:flutter/material.dart';
67+
68+
class LoginScreen extends StatefulWidget {
69+
@override
70+
_State createState() => _State();
71+
}
72+
73+
class _State extends State<LoginScreen> {
74+
TextEditingController nameController = TextEditingController();
75+
TextEditingController passwordController = TextEditingController();
76+
77+
@override
78+
Widget build(BuildContext context) {
79+
return Scaffold(
80+
appBar: AppBar(
81+
title: Text('Login'),
82+
),
83+
body: Padding(
84+
padding: EdgeInsets.all(10),
85+
child: ListView(
86+
children: <Widget>[
87+
Container(
88+
alignment: Alignment.center,
89+
padding: EdgeInsets.all(10),
90+
child: Text(
91+
'TutorialKart',
92+
style: TextStyle(
93+
color: Colors.blue,
94+
fontWeight: FontWeight.w500,
95+
fontSize: 30),
96+
)),
97+
Container(
98+
alignment: Alignment.center,
99+
padding: EdgeInsets.all(10),
100+
child: Text(
101+
'Sign in',
102+
style: TextStyle(fontSize: 20),
103+
)),
104+
Container(
105+
padding: EdgeInsets.all(10),
106+
child: TextField(
107+
controller: nameController,
108+
decoration: InputDecoration(
109+
border: OutlineInputBorder(),
110+
labelText: 'User Name',
111+
),
112+
),
113+
),
114+
Container(
115+
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
116+
child: TextField(
117+
obscureText: true,
118+
controller: passwordController,
119+
decoration: InputDecoration(
120+
border: OutlineInputBorder(),
121+
labelText: 'Password',
122+
),
123+
),
124+
),
125+
FlatButton(
126+
onPressed: () {
127+
//forgot password screen
128+
},
129+
textColor: Colors.blue,
130+
child: Text('Forgot Password'),
131+
),
132+
Container(
133+
height: 50,
134+
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
135+
child: RaisedButton(
136+
textColor: Colors.white,
137+
color: Colors.blue,
138+
child: Text('Login'),
139+
onPressed: () {
140+
print(nameController.text);
141+
print(passwordController.text);
142+
},
143+
)),
144+
Container(
145+
child: Row(
146+
children: <Widget>[
147+
Text('Does not have account?'),
148+
FlatButton(
149+
textColor: Colors.blue,
150+
child: Text(
151+
'Sign in',
152+
style: TextStyle(fontSize: 20),
153+
),
154+
onPressed: () {
155+
//signup screen
156+
},
157+
)
158+
],
159+
mainAxisAlignment: MainAxisAlignment.center,
160+
))
161+
],
162+
)));
163+
}
164+
}
165+
"""));
166+
sampleEntries.add(Sample(3, "Todo List", """
167+
168+
import 'package:flutter/material.dart';
169+
170+
class TodoScreen extends StatefulWidget {
171+
@override
172+
TodoScreenState createState() => TodoScreenState();
173+
}
174+
175+
class TodoScreenState extends State<TodoScreen> {
176+
List<String> todoItems = [];
177+
178+
@override
179+
Widget build(BuildContext context) {
180+
return Scaffold(
181+
appBar: AppBar(title: Text("Todo List")),
182+
body: createTodoList(),
183+
floatingActionButton: FloatingActionButton(
184+
onPressed: navigateToTodoScreen,
185+
tooltip: 'Add Todo',
186+
child: Icon(Icons.add)),
187+
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
188+
);
189+
}
190+
191+
void navigateToTodoScreen() {
192+
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
193+
return Scaffold(
194+
appBar: AppBar(title: Text('Add an item')),
195+
body: TextField(
196+
autofocus: true,
197+
onSubmitted: (val) {
198+
addTodoItem(val);
199+
Navigator.pop(context);
200+
},
201+
decoration: InputDecoration(
202+
hintText: 'Write todo text',
203+
contentPadding: const EdgeInsets.all(14.0)),
204+
),
205+
);
206+
}));
207+
}
208+
209+
void addTodoItem(String val) {
210+
if (val.length > 0) {
211+
setState(() {
212+
todoItems.add(val);
213+
});
214+
}
215+
}
216+
217+
Widget createTodoList() {
218+
return ListView.builder(
219+
itemCount: todoItems.length,
220+
itemBuilder: (context, index) {
221+
return createTodoItem(todoItems[index], index);
222+
});
223+
}
224+
225+
Widget createTodoItem(String todoText, int index) {
226+
return ListTile(
227+
title: Text(todoText),
228+
onTap: () => showAlertToRemove(index),
229+
);
230+
}
231+
232+
void showAlertToRemove(int index) {
233+
showDialog(
234+
context: context,
235+
builder: (BuildContext context) {
236+
return AlertDialog(
237+
title: Text("Are you want to delete this item?"),
238+
actions: <Widget>[
239+
FlatButton(
240+
child: Text('Cancel'),
241+
onPressed: () => Navigator.of(context).pop()),
242+
FlatButton(
243+
child: Text('Delete'),
244+
onPressed: () {
245+
deleteTodoItem(index);
246+
Navigator.of(context).pop();
247+
},
248+
)
249+
]);
250+
});
251+
}
252+
253+
void deleteTodoItem(int index) {
254+
setState(() {
255+
todoItems.removeAt(index);
256+
});
257+
}
258+
}
259+
260+
"""));
19261

20-
sampleEntries.add(new Sample(4, "Login Screen 1", "Description4"));
21-
sampleEntries.add(new Sample(5, "Login Screen 2", "Description5"));
22-
sampleEntries.add(new Sample(6, "Login Screen 3", "Description6"));
23262
return new Scaffold(
24263
appBar: new AppBar(
25264
title: new Text('Flutter Samples'),
@@ -42,16 +281,16 @@ class _HomeScreenState extends State<HomeScreen> {
42281
onTapped(int index, BuildContext context) {
43282
Navigator.push(
44283
context,
45-
MaterialPageRoute(builder: (context) => SampleScreen(sample: sampleEntries[index])),
284+
MaterialPageRoute(
285+
builder: (context) => SampleScreen(sample: sampleEntries[index])),
46286
);
47287
}
48-
49288
}
50289

51290
class Sample {
52291
final int id;
53292
final String title;
54-
final String description;
293+
final String sourceCode;
55294

56-
Sample(this.id, this.title, this.description);
295+
Sample(this.id, this.title, this.sourceCode);
57296
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /