import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Navigation',
initialRoute: '/switch',
routes: <String, WidgetBuilder>{
// '/': (BuildContext context) => Home(),
// '/search': (BuildContext context) => SearchBarDemo(),
'/switch': (BuildContext context) => SwitchDemo(),
// '/scrollMap': (BuildContext context) => scrollMap(),
},
);
}
}
class SwitchDemo extends StatefulWidget {
@override
State<StatefulWidget> createState() => FirstScreen();
}
class FirstScreen extends State<SwitchDemo> {
bool check = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Screen'),
),
body: Column(
children: <Widget>[
Container(
child: Center(
child: Container(
child: GestureDetector(
child: new Text(
'hello',
style: new TextStyle(
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.w900,
)),
),
width: 400,
height: 200,
),
),
width: 400,
color: Colors.red,
),
Switch(
value: check,
activeColor: Colors.red,
activeTrackColor: Colors.blue,
inactiveThumbColor: Colors.green,
inactiveTrackColor: Colors.orange, // 激活时原点颜色
materialTapTargetSize: MaterialTapTargetSize.padded,
onChanged: (bool val) {
setState(() {
check = !check;
if (check) {
print(check);
}
});
},
)
],
),
);
}
}