Skip to content

Commit aa05d61

Browse files
committed
flutter_lints added | Project restructured
1 parent c9f7a7e commit aa05d61

File tree

8 files changed

+123
-144
lines changed

8 files changed

+123
-144
lines changed

integration_test/app_test.dart

Lines changed: 0 additions & 36 deletions
This file was deleted.

integration_test/driver.dart

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/homepage.dart

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import 'package:custom_icon_with_bottombar/icons.dart';
2+
import 'package:custom_icon_with_bottombar/page_one.dart';
3+
import 'package:flutter/material.dart';
4+
5+
class MyHomePage extends StatefulWidget {
6+
const MyHomePage({Key key, this.title}) : super(key: key);
7+
8+
final String title;
9+
10+
@override
11+
_MyHomePageState createState() => _MyHomePageState();
12+
}
13+
14+
class _MyHomePageState extends State<MyHomePage> {
15+
int counter = 0;
16+
17+
void _incrementCounter() {
18+
setState(() {
19+
counter++;
20+
});
21+
}
22+
23+
int _currentIndex = 0;
24+
final List<Widget> _widgetList = [
25+
const PageOne(),
26+
const Text('Page Two'),
27+
const Text('Page Three'),
28+
const Text('Page Four'),
29+
];
30+
31+
@override
32+
Widget build(BuildContext context) {
33+
return Scaffold(
34+
appBar: AppBar(
35+
title: Text(widget.title),
36+
),
37+
body: _widgetList[_currentIndex],
38+
floatingActionButton: FloatingActionButton(
39+
onPressed: _incrementCounter,
40+
tooltip: 'Increment',
41+
child: const Icon(Icons.add),
42+
),
43+
bottomNavigationBar: BottomNavigationBar(
44+
unselectedIconTheme: IconThemeData(color: Colors.grey[400]),
45+
selectedIconTheme: const IconThemeData(color: Colors.black),
46+
unselectedLabelStyle: TextStyle(color: Colors.grey[400]),
47+
selectedLabelStyle: const TextStyle(color: Colors.black),
48+
fixedColor: Colors.green,
49+
type: BottomNavigationBarType.fixed,
50+
onTap: onTapped,
51+
currentIndex: _currentIndex,
52+
items: const [
53+
BottomNavigationBarItem(icon: Icon(MyFlutterApp.home), label: 'Home'),
54+
BottomNavigationBarItem(
55+
icon: Icon(MyFlutterApp.saved), label: 'Saved'),
56+
BottomNavigationBarItem(
57+
icon: Icon(MyFlutterApp.download), label: 'Downloads'),
58+
BottomNavigationBarItem(
59+
icon: Icon(MyFlutterApp.user), label: 'Profile'),
60+
],
61+
),
62+
);
63+
}
64+
65+
void onTapped(int index) {
66+
setState(() {
67+
_currentIndex = index;
68+
});
69+
}
70+
}

lib/main.dart

Lines changed: 5 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,23 @@
11
import 'package:flutter/material.dart';
2-
import 'icons.dart';
2+
import 'homepage.dart';
33

44
void main() {
5-
runApp(MyApp());
5+
runApp(const MyApp());
66
}
77

88
class MyApp extends StatelessWidget {
9+
const MyApp({Key key}) : super(key: key);
10+
911
@override
1012
Widget build(BuildContext context) {
1113
return MaterialApp(
1214
title: 'Flutter Demo',
1315
theme: ThemeData(
1416
primarySwatch: Colors.blue,
1517
),
16-
home: MyHomePage(title: 'Tech With Sam Tutorials'),
17-
);
18-
}
19-
}
20-
21-
class MyHomePage extends StatefulWidget {
22-
MyHomePage({Key key, this.title}) : super(key: key);
23-
24-
final String title;
25-
26-
@override
27-
_MyHomePageState createState() => _MyHomePageState();
28-
}
29-
30-
class _MyHomePageState extends State<MyHomePage> {
31-
int _counter = 0;
32-
33-
void _incrementCounter() {
34-
setState(() {
35-
_counter++;
36-
});
37-
}
38-
39-
int _currentIndex = 0;
40-
List<Widget> _widgetList = [
41-
PageOne(),
42-
Container(child: Text('Page Two')),
43-
Container(child: Text('Page Three')),
44-
Container(child: Text('Page Four')),
45-
];
46-
47-
@override
48-
Widget build(BuildContext context) {
49-
return Scaffold(
50-
appBar: AppBar(
51-
title: Text(widget.title),
52-
),
53-
body: _widgetList[_currentIndex],
54-
floatingActionButton: FloatingActionButton(
55-
onPressed: _incrementCounter,
56-
tooltip: 'Increment',
57-
child: Icon(Icons.add),
58-
), // This trailing comma makes auto-formatting nicer for build methods.
59-
bottomNavigationBar: BottomNavigationBar(
60-
unselectedIconTheme: IconThemeData(color: Colors.grey[400]),
61-
selectedIconTheme: IconThemeData(color: Colors.black),
62-
unselectedLabelStyle: TextStyle(color: Colors.grey[400]),
63-
selectedLabelStyle: TextStyle(color: Colors.black),
64-
fixedColor: Colors.green,
65-
type: BottomNavigationBarType.fixed,
66-
onTap: onTapped,
67-
currentIndex: _currentIndex,
68-
items: [
69-
BottomNavigationBarItem(icon: Icon(MyFlutterApp.home), label: 'Home'),
70-
BottomNavigationBarItem(
71-
icon: Icon(MyFlutterApp.saved), label: 'Saved'),
72-
BottomNavigationBarItem(
73-
icon: Icon(MyFlutterApp.download), label: 'Downloads'),
74-
BottomNavigationBarItem(
75-
icon: Icon(MyFlutterApp.user), label: 'Profile'),
76-
],
77-
),
18+
home: const MyHomePage(title: 'Tech With Sam Tutorials'),
7819
);
7920
}
80-
81-
void onTapped(int index) {
82-
setState(() {
83-
_currentIndex = index;
84-
});
85-
}
8621
}
8722

88-
class PageOne extends StatelessWidget {
89-
const PageOne({Key key}) : super(key: key);
9023

91-
@override
92-
Widget build(BuildContext context) {
93-
return Scaffold(
94-
body: Center(
95-
child: Column(
96-
mainAxisAlignment: MainAxisAlignment.center,
97-
children: <Widget>[
98-
Text(
99-
'You have pushed the button this many times:',
100-
),
101-
Text(
102-
'5',
103-
style: Theme.of(context).textTheme.headline4,
104-
),
105-
ListTile(
106-
leading: Icon(MyFlutterApp.home),
107-
title: Text('This is a custom home icon')),
108-
ListTile(
109-
leading: Icon(MyFlutterApp.saved),
110-
title: Text('This is a custom saved icon'))
111-
],
112-
),
113-
),
114-
);
115-
}
116-
}

lib/page_one.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'package:flutter/material.dart';
2+
import 'icons.dart';
3+
4+
class PageOne extends StatelessWidget {
5+
const PageOne({Key key}) : super(key: key);
6+
7+
@override
8+
Widget build(BuildContext context) {
9+
return Scaffold(
10+
body: Center(
11+
child: Column(
12+
mainAxisAlignment: MainAxisAlignment.center,
13+
children: <Widget>[
14+
const Text('You have pushed the button this many times:'),
15+
Text(
16+
'5',
17+
style: Theme.of(context).textTheme.headline4,
18+
),
19+
const ListTile(
20+
leading: Icon(MyFlutterApp.home),
21+
title: Text('This is a custom home icon'),
22+
),
23+
const ListTile(
24+
leading: Icon(MyFlutterApp.saved),
25+
title: Text('This is a custom saved icon'),
26+
)
27+
],
28+
),
29+
),
30+
);
31+
}
32+
}

pubspec.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ packages:
8888
description: flutter
8989
source: sdk
9090
version: "0.0.0"
91+
flutter_lints:
92+
dependency: "direct dev"
93+
description:
94+
name: flutter_lints
95+
url: "https://pub.dartlang.org"
96+
source: hosted
97+
version: "1.0.4"
9198
flutter_test:
9299
dependency: "direct dev"
93100
description: flutter
@@ -103,6 +110,13 @@ packages:
103110
description: flutter
104111
source: sdk
105112
version: "0.0.0"
113+
lints:
114+
dependency: transitive
115+
description:
116+
name: lints
117+
url: "https://pub.dartlang.org"
118+
source: hosted
119+
version: "1.0.1"
106120
matcher:
107121
dependency: transitive
108122
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dev_dependencies:
3434
sdk: flutter
3535
integration_test:
3636
sdk: flutter
37+
flutter_lints: ^1.0.0
3738

3839
# For information on the generic Dart part of this file, see the
3940
# following page: https://dart.dev/tools/pub/pubspec

test/widget_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
import 'package:flutter/material.dart';
99
import 'package:flutter_test/flutter_test.dart';
10-
1110
import 'package:custom_icon_with_bottombar/main.dart';
1211

1312
void main() {
1413
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
1514
// Build our app and trigger a frame.
16-
await tester.pumpWidget(MyApp());
15+
await tester.pumpWidget(const MyApp());
1716

1817
// Verify that our counter starts at 0.
1918
expect(find.text('0'), findsOneWidget);

0 commit comments

Comments
 (0)