Flutter build not behaving as expected - flutter

I'm trying to make a note app but there is a yellow square showing on the screen.
I've included the main.dart code and also allnotesscreens.dart. I think there is something wrong with allnotesscreens code, but I don't know what.
Maybe _loadViewMode() part.
Why this problem is happening?!!!
Main.dart:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'providers/label_provider.dart';
import 'providers/note_provider.dart';
import 'package:provider/provider.dart';
import 'constants/app_constants.dart';
import 'screens/all_labels_screen.dart';
import 'screens/all_notes_screen.dart';
import 'screens/drawer_screen.dart';
main() {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
systemNavigationBarColor: ColorsConstant.grayColor,
),
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => NoteProvider()),
ChangeNotifierProvider(create: (_) => LabelProvider()),
],
builder: (context, child) => MaterialApp(
title: 'Note-App',
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.dark,
theme: customThemeData(context),
initialRoute: '/',
routes: {
'/': (context) => const AllNotesScreen(),
DrawerScreen.routeName: (context) => const DrawerScreen(),
AllLabelsScreen.routeName: (context) => const AllLabelsScreen(),
},
),
);
}
}
allnotesscreens.dart:
class AllNotesScreen extends StatefulWidget {
const AllNotesScreen({Key? key}) : super(key: key);
#override
State<AllNotesScreen> createState() => _AllNotesScreenState();
}
class _AllNotesScreenState extends State<AllNotesScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child:
Container(
height: 200,
width: 100,
color: Colors.yellow,
),
),
);
}
String _viewMode = ViewMode.staggeredGrid.name;
bool _isLoading = false;
final _scaffoldKey = GlobalKey<ScaffoldState>();
#override
void initState() {
super.initState();
setState(() {
_isLoading = true;
});
}
#override
void didChangeDependencies() {
super.didChangeDependencies();
Future _loadViewMode() async {
final prefs = await SharedPreferences.getInstance();
if (!prefs.containsKey('view-mode')) return;
setState(() {
_viewMode = prefs.getString('view-mode') ?? ViewMode.staggeredGrid.name;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: const Text(
"all notes",
style: TextStyleConstants.titleAppBarStyle,
),
actions: [
if (context
.watch<NoteProvider>()
.items
.isNotEmpty)
IconButton(
onPressed: () {
showSearch(
context: context,
delegate: NoteSearch(isNoteByLabel: false),
);
},
icon: const Icon(Icons.search),
),
IconButton(
onPressed: () async {
final result = await changeViewMode(_viewMode);
setState(() {
_viewMode = result;
});
},
icon: _viewMode == ViewMode.staggeredGrid.name
? const Icon(Icons.view_stream)
: const Icon(Icons.grid_view),
),
const SizedBox(
width: 6,
)
],
),
drawer: const DrawerScreen(),
body: _isLoading
? const Center(
child: CircularProgressIndicator(),
)
: RefreshIndicator(
onRefresh: () => refreshOrGetData(context),
child: Consumer<NoteProvider>(
builder: (context, noteProvider, child) =>
noteProvider.items.isNotEmpty
? NoteListViewWidget(
notes: noteProvider.items,
viewMode: _viewMode,
scaffoldContext: _scaffoldKey.currentContext!,
)
: child!,
child: const NoNoteUIWidget(
title: "your notes after adding will appear here",
),
),
),
floatingActionButton: FloatingActionButton(
child: linearGradientIconAdd,
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const EditNoteScreen(),
));
},
),
);
}
}
}

The first few lines of your _AllNotesScreenState class are why there's a yellow square; that's what you're telling it to build.
class _AllNotesScreenState extends State<AllNotesScreen> {
// this build function here is what is drawing to the screen
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child:
Container(
height: 200,
width: 100,
color: Colors.yellow,
),
),
);
}
Maybe it's just how you've pasted it in, but it appears as though you have a build function defined within the didChangeDependencies function. If you took it out of there, it would then make it apparent that you have two build functions defined for the class.
I'm assuming it's the second one that you actually want building.
#override
void didChangeDependencies() {
super.didChangeDependencies();
Future _loadViewMode() async {
final prefs = await SharedPreferences.getInstance();
if (!prefs.containsKey('view-mode')) return;
setState(() {
_viewMode = prefs.getString('view-mode') ?? ViewMode.staggeredGrid.name;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
...

Related

How to reflect the value from FutureProvider when certain UI onPressed?

I'm very new about Flutter and the library reiver_pod.
I want show Text("Hello World") on screen, only when floatingActionButton pressed with using FutureProvider but it's always shown even though the button has never been pressed ? How it come and how can I Fix it ?
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() {
runApp(const ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'FutureProvider',
theme: ThemeData(
textTheme: const TextTheme(bodyText2: TextStyle(fontSize: 50)),
),
home: HomePage(),
);
}
}
final futureProvider = FutureProvider<dynamic>((ref) async {
await Future.delayed(const Duration(seconds: 3));
return 'Hello World';
});
class HomePage extends ConsumerWidget {
#override
Widget build(BuildContext context, WidgetRef ref) {
final asyncValue = ref.watch(futureProvider);
return Scaffold(
appBar: AppBar(title: const Text('TEST')),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.refresh),
onPressed: () {
ref.refresh(futureProvider);
},
),
body: Center(
child: asyncValue.when(
error: (err, _) => Text(err.toString()),
loading: () => const CircularProgressIndicator(),
data: (data) {
print(data);
return Text(data.toString());//here
},
),
),
);
}
}
renewal code as follow:
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'dart:math';
void main() {
runApp(const ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'FutureProvider',
theme: ThemeData(
textTheme: const TextTheme(bodyText2: TextStyle(fontSize: 50)),
),
home: HomePage(),
);
}
}
final StateProvider<bool> pressProvider = StateProvider((ref) => false);
final futureProvider = FutureProvider<dynamic>((ref) async {
var intValue = Random().nextInt(100);
await Future.delayed(const Duration(seconds: 1));
return intValue.toString();
});
class HomePage extends ConsumerWidget {
#override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: AppBar(title: const Text('TEST')),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.refresh),
onPressed: () {
ref.read(pressProvider.notifier).update((state) => true);
ref.refresh(futureProvider);
},
),
body: Center(
child: ref.watch(pressProvider)
? Consumer(
builder: (context, ref, child) {
final asyncValue = ref.watch(futureProvider);
return asyncValue.when(
error: (err, _) => Text(err.toString()),
loading: () => const CircularProgressIndicator(),
data: (data) {
return Text(data.toString()); //here
},
);
},
)
: null),
);
}
}
You can use a bool to handle tap event like, FutureProvider will handle the UI update case.
class HomePage extends ConsumerWidget {
bool isPressed = false;
#override
Widget build(BuildContext context, WidgetRef ref) {
final asyncValue = ref.watch(futureProvider);
return Scaffold(
appBar: AppBar(title: const Text('TEST')),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.refresh),
onPressed: () {
isPressed = true;
ref.refresh(futureProvider);
},
),
body: Center(
child: isPressed
? asyncValue.when(
error: (err, _) => Text(err.toString()),
loading: () => const CircularProgressIndicator(),
data: (data) {
print(data);
return Text(data.toString()); //here
},
)
: null,
),
);
}
}

Flutter Switch will not work inside AlertBox

I am having a problem where when I try to use a switch widget it will not work properly inside of an alert box as in it does not switch over to the second state it just bounces whenever I try to flick it. I am wondering if this is because there is a problem with the switch itself or how I displayed it in the box? Thanks!
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(),
home: SwitchDemo(),
);
}
}
class SwitchDemo extends StatefulWidget {
const SwitchDemo({Key key}) : super(key: key);
#override
State<StatefulWidget> createState() => new _TabsPageState();
}
class _TabsPageState extends State<SwitchDemo> {
bool isInstructionView;
#override
void initState() {
super.initState();
isInstructionView = Global.shared.isInstructionView;
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("add data"),
),
body: Container(
child: TextButton(
child: Text('Open Alert Box'),
onPressed: () => {
showDialog(
context: context,
builder: (BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width / 20,
vertical:
MediaQuery.of(context).size.height / 20,
),
child: AlertDialog(
content: Container(
child: Switch(
value: isInstructionView,
onChanged: (bool isOn) {
if (isInstructionView == false) {
} else if (isInstructionView == true) {}
setState(() {
isInstructionView = isOn;
Global.shared.isInstructionView = isOn;
isOn = !isOn;
});
},
activeColor: Colors.blue,
inactiveTrackColor: Colors.grey,
inactiveThumbColor: Colors.grey,
),
),
),
);
})
}),
));
}
}
class Global {
static final shared = Global();
bool isInstructionView = false;
}
Wrap you AlertDialog with StatefulBuilder.
here is full code:
import 'package:flutter/material.dart';
class SwitchDemo extends StatefulWidget {
const SwitchDemo({Key? key}) : super(key: key);
#override
State<StatefulWidget> createState() => new _TabsPageState();
}
class _TabsPageState extends State<SwitchDemo> {
late bool isInstructionView;
#override
void initState() {
super.initState();
isInstructionView = Global.shared.isInstructionView;
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("add data"),
),
body: Container(
child: TextButton(
child: Text('Open Alert Box'),
onPressed: () => {
showDialog(
context: context,
builder: (BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width / 20,
vertical: MediaQuery.of(context).size.height / 20,
),
child: StatefulBuilder(builder: (context, setState) {
return AlertDialog(
content: Container(
child: Switch(
value: isInstructionView,
onChanged: (bool isOn) {
print(isInstructionView);
setState(() {
isInstructionView = !isInstructionView;
});
},
activeColor: Colors.blue,
inactiveTrackColor: Colors.grey,
inactiveThumbColor: Colors.grey,
),
),
);
}),
);
},
)
}),
));
}
}
class Global {
static final shared = Global();
bool isInstructionView = false;
}
Does it answer your question?
ref: https://stackoverflow.com/a/57240941/10157127

Initstate isn't referenced Flutter Problem

i am facing a new problem with my code, and honestly, I cant figure out where is my mistake , i have made the exact same widget in another file, and runs perfectly.
I'm starting to believe that there is one problem with some widgets maybe.
I paste my code so you can check it out and tell me where is my mistake (very common ) or maybe is some widget/ line of code that is breaking the code.
import 'package:flutter/material.dart';
void main(List<String> args) {
runApp(MaterialApp(
home: Scaffold(
body: Products(),
),
));
}
class Products extends StatefulWidget {
Products({Key key}) : super(key: key);
#override
_ProductsState createState() => _ProductsState();
}
Class _ProductsState extends State<Products> {
#override
Widget build(BuildContext context) {
bool valoractual;
#override
void initState() {
super.initState();
valoractual = false;
}
return Scaffold(
appBar: AppBar(
backgroundColor: Color.fromRGBO(239, 180, 185, 1),
actions: <Widget>[
Icon(
Icons.search,
size: 25,
),
Switch(
activeColor: Colors.white,
inactiveThumbColor: Colors.blue[900],
value: valoractual,
onChanged: (bool cambio) {
setState(() {
valoractual = cambio;
});
//cambiovalor();
if (valoractual) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
content: Text(" delete option"),
actions: [
FlatButton(
onPressed: () {
print("****************");
print(valoractual);
Navigator.of(context).pop();
return valoractual;
},
child: Text("Continue"),
)
],
),
);
} else {
showDialog(
context: context,
builder: (context) => AlertDialog(
content:
Text("view option"),
actions: [
FlatButton(
onPreenter code heressed: () {
print("****************");
print(valoractual);
Navigator.of(context).pop();
return valoractual;
},
child: Text("Aceptar"),
)
],
),
);
}
},
),
Icon(Icons.delete, size: 20),
],
),
body: Container(
margin: EdgeInsets.only(top: 10),
child: Text("this is sample text"),
),
);
}
}
used the following code style
Happy Coding :)
try to put your initState function out of the build function
like
Class _ProductsState extends State<Products> {
bool valoractual;
#override
void initState() {
super.initState();
valoractual = false;
}
#override
Widget build(BuildContext context) {
return Scaffold(

Height of the status bar always returns 0

When calling MediaQuery.of(context).padding.top in the parent widget (ProductsOverviewScreen) the value returned is as expected - 24. But when calling the same property from a nested widget (ProductsGrid) of the parent that we are talking about the value is always 0. Is this normal behavior?
products_overview_screen.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../widgets/app_drawer.dart';
import '../screens/cart_screen.dart';
import '../widgets/products_grid.dart';
import '../widgets/badge.dart';
import '../providers/cart.dart';
import '../providers/products_provider.dart';
enum FilterOptions {
showAll,
onlyFavorites,
}
class ProductsOverviewScreen extends StatefulWidget {
#override
_ProductsOverviewScreenState createState() => _ProductsOverviewScreenState();
}
class _ProductsOverviewScreenState extends State<ProductsOverviewScreen> {
bool _showFavorites = false;
bool _isLoading = false;
bool _isInit = false;
#override
void initState() {
// Future.delayed(Duration(seconds: 1), () {
// Provider.of<Products>(context).fetchAndSetProducts();
// });
super.initState();
}
#override
void didChangeDependencies() {
if (!_isInit) {
setState(() {
_isLoading = true;
});
Provider.of<Products>(context).fetchAndSetProducts().then((_) {
setState(() {
_isLoading = false;
});
});
}
_isInit = true;
super.didChangeDependencies();
}
Future<void> refreshProducts(BuildContext context) async {
await Provider.of<Products>(context, listen: false).fetchAndSetProducts();
}
#override
Widget build(BuildContext context) {
final scaffoldKey = GlobalKey();
final appBar = AppBar(
title: Text('My Shop'),
actions: <Widget>[
Consumer<Cart>(
builder: (ctx, cart, child) => Badge(
child: child,
value: cart.length.toString(),
),
child: IconButton(
onPressed: () {
final scaffoldState = scaffoldKey.currentState as ScaffoldState;
scaffoldState.hideCurrentSnackBar();
Navigator.of(context).pushNamed(CartScreen.routeName);
},
icon: Icon(
Icons.shopping_cart,
color: Theme.of(context).accentColor,
),
),
),
PopupMenuButton(
onSelected: (FilterOptions selectedValue) {
setState(() {
if (selectedValue == FilterOptions.onlyFavorites) {
_showFavorites = true;
} else {
_showFavorites = false;
}
});
},
icon: Icon(Icons.more_vert),
itemBuilder: (_) => [
PopupMenuItem(
child: Text('Only Favorites'),
value: FilterOptions.onlyFavorites),
PopupMenuItem(
child: Text('Show All'),
value: FilterOptions.showAll,
),
],
),
],
);
return Scaffold(
key: scaffoldKey,
appBar: appBar,
drawer: AppDrawer(),
body: _isLoading
? Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: () => refreshProducts(context),
child: ProductsGrid(_showFavorites, appBar.preferredSize.height),
),
);
}
}
//56
products_grid.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/products_provider.dart';
import '../widgets/product_item.dart';
class ProductsGrid extends StatelessWidget {
final bool _showFavorites;
final double _appBarHeight;
ProductsGrid(this._showFavorites, this._appBarHeight);
#override
Widget build(BuildContext context) {
final productsData = Provider.of<Products>(context);
final products =
_showFavorites ? productsData.favoriteItems : productsData.items;
final mediaQuery = MediaQuery.of(context);
return productsData.items.isEmpty
? SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Container(
width: mediaQuery.size.width,
height: mediaQuery.size.height -
mediaQuery.padding.top -
_appBarHeight,
// child: Center(
// child: Text(
// 'There are no products.',
// style: TextStyle(
// color: Colors.grey,
// fontSize: 16,
// ),
// ),
// ),
),
)
: GridView.builder(
padding: const EdgeInsets.all(15),
itemCount: products.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemBuilder: (ctx, index) => ChangeNotifierProvider.value(
value: products[index],
child: ProductItem(),
),
);
}
}
You can copy paste run full code below
You can use MediaQueryData.fromWindow(window).padding.top
code snippet
import 'dart:ui';
...
final statusbarHeight2 = MediaQueryData.fromWindow(window).padding.top;
working demo
full code
import 'package:flutter/material.dart';
import 'dart:ui';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: ProductsOverviewScreen(title: 'Flutter Demo Home Page'),
);
}
}
class ProductsOverviewScreen extends StatefulWidget {
ProductsOverviewScreen({Key key, this.title}) : super(key: key);
final String title;
#override
_ProductsOverviewScreenState createState() => _ProductsOverviewScreenState();
}
class _ProductsOverviewScreenState extends State<ProductsOverviewScreen> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
final statusbarHeight1 = MediaQueryData.fromWindow(window).padding.top;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ProductsGrid(),
Text(
'$statusbarHeight1',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
class ProductsGrid extends StatelessWidget {
const ProductsGrid({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
final statusbarHeight2 = MediaQueryData.fromWindow(window).padding.top;
return Text(
'$statusbarHeight2',
);
}
}
You can get all information about window using window object that provided by dart:ui. Here an example of finding exact size of status bar;
Firstly add this top of the dart file:
import 'dart:ui';
And use window object to find height of the status bar:
final statusBarHeight = window.padding.top / window.devicePixelRatio;

SharedPreferences value needs to be reset every other time

So,in this included flutter code,I am using a if loop in checkFirstSeen() to set my seen boolean to a value. This will then set my SharedPreferences value for the app. However,on every other restart of the application,I have to press the GotoHomepage button as opposed to it working automatically based off of the SharedPreferences value that was set. How can I fix this?
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:audiotest/UI/homepage.dart';
void main() => runApp(new MaterialApp(
title: "TestAudio",
initialRoute: '/intro_route',
routes: {
'/intro_route': (context) => IntroScreen(),
'/homescreen_route': (context) => MainPersistentTabBar2(),
}));
class IntroScreen extends StatefulWidget {
#override
IntroScreenstate2 createState() => IntroScreenstate2();
}
class IntroScreenstate2 extends State<IntroScreen> {
bool buttonstatus = true;
Future checkFirstSeen() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool seen = (prefs.getBool('seen') ?? false);
prefs.setBool('seen', false);
if (buttonstatus == false) {
prefs.setBool('seen', true);
}
if (seen == true) {
Navigator.pushNamed(context, '/homescreen_route');
} else {
}
}
#override
void initState() {
super.initState();
new Timer(new Duration(milliseconds: 1), () {
checkFirstSeen();
});
}
#override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Text('This is the placeholder for the TOS'),
new MaterialButton(
child: new Text('Go to Home Page'),
onPressed: () {
buttonstatus = false;
checkFirstSeen();
//Navigator.pushNamed(context, '/homescreen_route');
},
)
],
),
),
);
}
}
You can copy paste run full code below
You can get seen in main() and check seen directly in initialRoute
code snippet
bool seen;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
seen = await prefs.getBool("seen");
await prefs.setBool("seen", true);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
...
initialRoute:
seen == false || seen == null ? "/intro_route" : "/homescreen_route",
routes: {
'/homescreen_route': (context) => MainPersistentTabBar2(
title: "demo",
),
"/intro_route": (context) => IntroScreen(),
},
);
}
}
working demo
full code
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/services.dart';
bool seen;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
seen = await prefs.getBool("seen");
await prefs.setBool("seen", true);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute:
seen == false || seen == null ? "/intro_route" : "/homescreen_route",
routes: {
'/homescreen_route': (context) => MainPersistentTabBar2(),
"/intro_route": (context) => IntroScreen(),
},
);
}
}
class MainPersistentTabBar2 extends StatefulWidget {
#override
MainPersistentTabBarState2 createState() => MainPersistentTabBarState2();
}
class MainPersistentTabBarState2 extends State<MainPersistentTabBar2> {
Brightness brightness;
#override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.dark,
),
home: DefaultTabController(
length: 4,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
isScrollable: true,
tabs: <Widget>[
Container(
width: 90,
height: 40,
alignment: Alignment.center,
child: Text("Session 1"),
),
Container(
width: 90,
height: 40,
alignment: Alignment.center,
child: Text("Session 2"),
),
Container(
width: 90,
height: 40,
alignment: Alignment.center,
child: Text("Session 3"),
),
Container(
width: 90,
height: 40,
alignment: Alignment.center,
child: Text("Session 4"),
),
],
),
title: Text('Own The Tone '),
/*actions: <Widget>[
PopupMenuButton<String>(
onSelected: _choiceAction,
itemBuilder: (BuildContext context) {
return Constants.choices.map((String choice) {
return PopupMenuItem<String>(
value: choice,
child: Text(choice),
);
}).toList();
},
)
],*/
),
body: TabBarView(
children: <Widget>[
FirstScreen(),
Center(child: Text("Sample two")),
Center(child: Text("Sample three")),
Center(child: Text("Sample four")),
],
),
),
),
);
}
// This area controls the settings menus
/* void _choiceAction(String choice) {
if (choice == Constants.about) {
Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('About the app'),
),
body: new PageView(),
);
}));
} else if (choice == Constants.settings) {
Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Settings'),
),
body: new Container(
child: Center(
child: Text('placeholder'),
)),
);
}));
}
}*/
}
class FirstScreen extends StatefulWidget {
#override
_FirstScreenState createState() => _FirstScreenState();
}
class _FirstScreenState extends State<FirstScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("First Screen"),
),
body: Text("First"));
}
}
class IntroScreen extends StatefulWidget {
#override
_IntroScreenState createState() => _IntroScreenState();
}
class _IntroScreenState extends State<IntroScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Introduction"),
),
body: Text("Intro"));
}
}