我试过底部导航栏。但是,我收到了一个意外的警告。
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatefulWidget(),
theme: ThemeData(
primaryColor: Colors.blueAccent,
brightness: Brightness.light,
),
debugShowCheckedModeBanner: false,
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIndex = 0;
final _widgetOptions = [
ListGenerate(),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
systemNavigationBarColor: Colors.blue,
statusBarColor: Colors.transparent,
));
return Scaffold(
body: Column(
children: <Widget>[
searchSection,
_widgetOptions.elementAt(_selectedIndex),
],
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.info),
title: Text('Info'),
),
BottomNavigationBarItem(
icon: Icon(Icons.today),
title: Text('Scheule'),
),
BottomNavigationBarItem(
icon: Icon(Icons.location_on),
title: Text('Location'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.white,
onTap: _onItemTapped,
unselectedItemColor: Colors.white70,
backgroundColor: Colors.blueAccent,
),
);
}
}
Widget searchSection = Container(
padding: const EdgeInsets.all(32),
child: Column(
children: <Widget>[
Container(
padding: const EdgeInsets.only(top: 4, bottom: 4, right: 8, left: 8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(Icons.dehaze, color: Colors.grey,),
Text('Search', style:
TextStyle(
color: Colors.grey,
),
),
Container(
height: 42,
width: 42,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(
'https://www.w3schools.com/howto/img_avatar.png'
)
),
),
),
],
),
)
],
)
);
class ListGenerate extends StatefulWidget {
@override
_ListGenerateState createState() => _ListGenerateState();
}
class _ListGenerateState extends State<ListGenerate> {
List<String> litems = ["1","2","Third","4"];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext context, int index) {
return new Text(litems[index]);
}
),
],
),
),
);
}
}
发布于 2019-06-10 15:42:24
void main() => runApp(MyApp());
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatefulWidget(),
theme: ThemeData(
primaryColor: Colors.blueAccent,
brightness: Brightness.light,
),
debugShowCheckedModeBanner: false,
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIndex = 0;
final _widgetOptions = [
ListGenerate(),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
systemNavigationBarColor: Colors.blue,
statusBarColor: Colors.transparent,
));
return Scaffold(
body: Column(
children: <Widget>[
searchSection,
Expanded(child: _widgetOptions.elementAt(_selectedIndex)),
],
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.info),
title: Text('Info'),
),
BottomNavigationBarItem(
icon: Icon(Icons.today),
title: Text('Scheule'),
),
BottomNavigationBarItem(
icon: Icon(Icons.location_on),
title: Text('Location'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.white,
onTap: _onItemTapped,
unselectedItemColor: Colors.white70,
backgroundColor: Colors.blueAccent,
),
);
}
}
Widget searchSection = Container(
padding: const EdgeInsets.all(32),
child: Column(
children: <Widget>[
Container(
padding: const EdgeInsets.only(top: 4, bottom: 4, right: 8, left: 8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(
Icons.dehaze,
color: Colors.grey,
),
Text(
'Search',
style: TextStyle(
color: Colors.grey,
),
),
Container(
height: 42,
width: 42,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(image: NetworkImage('https://www.w3schools.com/howto/img_avatar.png')),
),
),
],
),
)
],
));
class ListGenerate extends StatefulWidget {
@override
_ListGenerateState createState() => _ListGenerateState();
}
class _ListGenerateState extends State<ListGenerate> {
List<String> litems = ["1", "2", "Third", "4"];
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: litems.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: new Text(litems[index]),
);
},
);
}
}https://stackoverflow.com/questions/-100006976
复制相似问题