import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'RoleInfoPage.dart'; class RolePage extends StatefulWidget { Map? thisParams; RolePage({super.key, this.thisParams}); @override State createState() => _RolePageState(); } class _RolePageState extends State { List list = ["小猫娘", "护士小雨", "人妻李慧佳","杜月儿"]; @override void initState() { // TODO: implement initState super.initState(); } @override void dispose() { // TODO: implement dispose super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( title: Text( "角色选择", style: TextStyle(fontSize: 18), ), backgroundColor: Colors.white, centerTitle: true, actions: [ GestureDetector( onTap: () {}, child: Container( margin: const EdgeInsets.only(right: 20), width: 70, height: 50, alignment: Alignment.center, decoration: BoxDecoration( color: Color(0xFF006CFF), borderRadius: BorderRadius.all(Radius.circular(8.0))), child: Text( "添加角色", style: TextStyle(color: Colors.white), ), ), ) ], ), body: Container( child: Column( children: [ Container( width: double.infinity, height: 1, color: Color(0xFFDFDFDF), ), Expanded( child: Container( alignment: Alignment.topCenter, child: ListView.builder( itemCount: list.length, itemBuilder: (context, index) { return _item(index); }), )), ], ), )); } _item(index) { return GestureDetector( onTap: () { if (index == 0) { Navigator.pushNamed(context, "/HomePage"); }else{ Navigator.push( context, MaterialPageRoute( //导航打开新视图 builder: (context) => RoleInfoPage(thisParams: {"RoleId": index,"RoleName":list[index]}) )); } }, child: Container( margin: const EdgeInsets.only(top: 20,left: 20,right: 20), width: 70, height: 50, alignment: Alignment.center, decoration: BoxDecoration( color: Color(0xFF006CFF), borderRadius: BorderRadius.all(Radius.circular(8.0))), child: Text( list[index], style: TextStyle(color: Colors.white), ), ), ); } }