Skip to content

Commit

Permalink
combine tab
Browse files Browse the repository at this point in the history
  • Loading branch information
theachoem committed Feb 11, 2024
1 parent 3a79418 commit d2e78ca
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
48 changes: 47 additions & 1 deletion lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_projection/pages/custom_paints/custom_paints_page.dart';
import 'package:flutter_projection/pages/transform/transform_page.dart';

class App extends StatelessWidget {
Expand All @@ -10,7 +11,52 @@ class App extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: const TransformPage(),
home: const HomePage(),
);
}
}

class HomePage extends StatefulWidget {
const HomePage({super.key});

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
int index = 0;

final pages = [
const CustomPaintsPage(),
const TransformPage(),
];

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: DropdownMenu<String>(
onSelected: (value) {
setState(() {
index = pages.indexWhere((e) {
return e.runtimeType.toString() == value;
});
});
},
dropdownMenuEntries: pages.map(
(e) {
return DropdownMenuEntry(
value: e.runtimeType.toString(),
label: e.runtimeType.toString(),
);
},
).toList(),
),
),
body: IndexedStack(
index: index,
children: pages,
),
);
}
}
11 changes: 4 additions & 7 deletions lib/pages/custom_paints/custom_paints_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ class CustomPaintsPage extends StatelessWidget {
return DefaultTabController(
length: tabs.length,
child: Scaffold(
appBar: AppBar(
title: const Text("Custom Paint"),
bottom: TabBar(
tabs: tabs.map((e) {
return Tab(text: e.runtimeType.toString());
}).toList(),
),
appBar: TabBar(
tabs: tabs.map((e) {
return Tab(text: e.runtimeType.toString());
}).toList(),
),
body: TabBarView(children: tabs),
),
Expand Down
11 changes: 4 additions & 7 deletions lib/pages/transform/transform_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ class TransformPage extends StatelessWidget {
return DefaultTabController(
length: tabs.length,
child: Scaffold(
appBar: AppBar(
title: const Text("Transform"),
bottom: TabBar(
tabs: tabs.map((e) {
return Tab(text: e.runtimeType.toString());
}).toList(),
),
appBar: TabBar(
tabs: tabs.map((e) {
return Tab(text: e.runtimeType.toString());
}).toList(),
),
body: TabBarView(children: tabs),
),
Expand Down

0 comments on commit d2e78ca

Please sign in to comment.